|
almost every one has used following line
#include < iostream > //or others
i don't know why don't use dot h, so
#include < iostream.h >
if say, file name < iostream.h > has been used, but it can be another name (i.e. iosteam_0_1_2.h)
my question is,
why don't use .h for the head file? is there any advantages?
thx
includeh10
|
|
|
|
|
<iostream> and <iostream.h> are different versions of the file; <iostream> is preferred and conforms closely with the current ANSI/ISO standard. <iostream.h> is older and provided for backwards compatibility. Use <iostream> for all new code.
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
Adding to what Nick said, the new headers were part of the first C++ standard ( and therefore the .h headers are non-standard C++ ), and they wrap everything in namespace std, so if for example you wanted to use cout, you'd need to use iostream AND put using std::cout; in your code, or reference cout through std:: every time you use it.
There is also the option of using the entire std namespace, but that's not something that real programmers do.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
sometimes i am blocked there for hours just for a stupid error, i think it comes again.
i need to access a char buffer with high speed, now it uses almost 37 ms, i want to reduce it. to do so, i do several tests to find the points of time consumer.
one test is very strange as following.
const char*pszBuf points to a null-based string, size is 354,737 bytes (from opening a file) and created by new, out of scope of following function:
function code:
char*pszFirst=(char*)pszBuf;
char*pszLast=(char*)&pszFirst[strlen(pszFirst)];
UINT uTime=::GetTickCount();
for(int i=0;i<1000;i++) //loop for getting right time
{
//line 0
pszLast=(char*)&pszFirst[strlen(pszFirst)];
char*psz=pszFirst;
//line 1
while (psz < pszLast) psz++;
}
uTime=::GetTickCount()-uTime; //check time here
run the code
a). keep both line 0 and line 1, uTime is 8,570 ms
b). delete line 0, keep line 1, uTime is almost 0
c). delete line 1, keep line 0, uTime is almost 0
that is: 0 + 0 = 8570
what is wrong? can u beleave that?
thx
includeh10
|
|
|
|
|
strlen() is slowing your code. Try calculating the string length outside the loop.
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2001 Microsoft Corporation. All rights reserved.
|
|
|
|
|
it is a test, that is why inside loop.
i can put strlen out of loop, but can't put it out of my program.
includeh10
|
|
|
|
|
includeh10 wrote:
i can put strlen out of loop, but can't put it out of my program.
That's what Nick said. It's being called over and over when you only need to call it once. It is the bottleneck in this code because you call it over and over needlessly.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
Although I agree with Nick and Christian that the strlen should be out of the loop I also think it's really besides the point.
You're wondering how 0 + 0 gets to be 8570, right? And putting strlen inside a loop here is just for testing purposes, right? You would never put strlen inside a loop in your final program, right? Promise?;P
Anyway, I can't see anything "wrong" with the code (except that you didn't put it into pre-tags which greatly improves readability ). I put it into my VC++6.0, and got pp. 4200 ms for both lines and app. half for each of the lines alone - all in debug builds. In release builds all timings were 0 msecs.
My best shot would be that optimization is playing you a trick. Are you sure all optimizations are turned off? Or perhaps some of your other code only forces the optimizer to keep the code when both lines are present.
I'm probably wrong, but hey, that's the story of my life.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I think that Visual C++ does some trivial optimisation even in debug builds.
When line 0 is deleted, it is trivial for the compiler to know that line 1 does nothing and the the whole loop is useless.
For the other case (line 1 deleted), I don't see how it can be "optimized" except if intrinsic inline functions are enabled.
The best thing to do is to take a look at the assembler code while debugging. You will see what the compiler has generate.
At first, I would think that the compiler has detected that the loop is useless when timing is really near 0ms.
Probaly when you have both lines, the complexity is higher than what VC will try to optimize...
Philippe Mori
|
|
|
|
|
Hi.
I am becoming more familiar with Win32 API especially for winsock and core Windows including threads, processes, and DLL. I began learning programming about a year ago and my first and currently more proficient language is C++. I have no prior programming experience and not knowledge of C. Nonetheless, Win32 API and other Windows programming tools as well and good DOS and linux programs all make use of C run-time library.
I would like to know ways to allocate and deallocate a chunk of memory space. In C++, I am familiar with the new and delete operators. However, you have to define the data type you before allocating memory. I C, I believe you can allocate a chunk of memory (BYTE data type?) and store anything there. Furthermore, you can use function, I believe free(), to free the memory.
What are some ways to allocate/deallocate memory using C/C++ other than new/delete?
Thanks,
Kuphryn
|
|
|
|
|
void * ptr = malloc(NumberofBytes);
There is also calloc, and GlobalAlloc
Look 'em up to see the usage.
|
|
|
|
|
C : malloc, realloc, calloc, free
C++ : new, delete, GlobalAlloc, GlobalFree, LocalAlloc, LocalFree...
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Okay. Thanks.
Wow. I have not seen GlobalAlloc, GlobalFree, LocalAlloc, or LocalFree in my limited experience using C++. I think the only book that goes over them is by Bjarne Stroustrup.
Kuphryn
|
|
|
|
|
GlobalAlloc, LocalAlloc etc are actually part of the Win32 API, NOT the C++ language - they can be used from any language that can call a function just about (Visual Basic anyone )
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Stuart Dootson wrote:
ForumVisual C++
Subject:Re: Memory Allocation :: C/C++
Sender:Stuart Dootson
Date:2:44 15 Aug '02
GlobalAlloc, LocalAlloc etc are actually part of the Win32 API, NOT the C++ language - they can be used from any language that can call a function just about (Visual Basic anyone )
every 5th vb instruction is appended with one of these
Rutger Ellen
|
|
|
|
|
|
Is there a way to send send messages to controls in an HTML view?
I want to display a page and programmatically emulate button clicks
on controls and links etc.
Happy programming!!
|
|
|
|
|
Does anybody know of an easy way to change the font color of Static Text within mfc dialogs? It seems such a trivial thing to do, yet I have not yet found a way of doing it...
Thanks for your help.
Steve.
|
|
|
|
|
|
My code is completely unicode enabled using the _TCHAR style macro's. However, when I type Japaniese (or any other double byte characters for that matter) my dialogs still show the corrupted single byte text.
Can someone direct me to documentation or give me a tip on how to get edit controls, lists boxs, etc. to show the proper dbcs character sets?
The build I tested on was using both #define UNICODE and #define _UNICODE
This is my first attempt at making an app that supports dbcs characters, so I appologize if this is a basic question.
Thanks!
. djrisc .
|
|
|
|
|
I forgot to include that I also tried to use #define _MBCS
This generated some compiler issues due to type definition changes. However, this kind of boggles me since both ASCII and UNICODE works smoothly.
. djrisc .
|
|
|
|
|
You need to change the font in the dialog resource to "MS Shell Dlg". VC 6 sets it to "MS Sans Serif" which doesn't have DBCS support. Sadly, you'll have to change the font name every time you change the resources, because VC 6 doesn't understand Shell Dlg and will reset it back to Sans Serif.
--Mike--
Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Mike,
Perfect! Thanks a million! Worked like a charm.
. djrisc .
|
|
|
|
|
Does someone have some sample C++ programs (Visual C.NET) that do some real simple dialogue interface to a DOS program ?
I have a command line DOS C++ program that opens an input file (fopen()) reads it, manipulates it and writes it out using the same file name but in a different directory. Also, there can be some input required by the user during the processing.
I need a dialogue window that browses for a file name, followed by a dialogue that browses for a directory path (output directory) and can pass these values to my program. Also the ability to trigger a dialogue during my processing.
I am overwhelmed by all the examples provided by microsoft, when all I need is this !
Do any of you seasoned Windows C++ programmers have a shell that I can work with ?
Any comments or advice welcome
Thanks
|
|
|
|
|
I am buildng a COM dll that uses C++ dll. When registering the component C++ gives me an error - unable to locate a C++ dll (although compiling and linking were fine). How can I modify Project setting or environmental variables to tell RegSvr32 where to look for the dll?
Thanks,
This is the error I am getting:
Performing registration
RegSvr32: LoadLibrary(".\Debug\MyCOM1.dll") failed.
GetLastError returns 0x0000007e.
OleMainTreadWndName: RegSVR32.exe - Unable to locate DLL
|
|
|
|