|
wow. It really works. Thanks. Just wanna ask if you dont mind. Why do we need to add windows.h. I always see codes which add windows.h eventhough it is just a hello world printf statement. Just kinda curious. Thanks again.
|
|
|
|
|
Kogee San wrote: Why do we need to add windows.h.
This is because the Wininet.h file use some other data types such as LPVOID. This is defined in some other header files. For getting the definition of such items we need to include the windows.h
|
|
|
|
|
Kogee San wrote: I always see codes which add windows.h eventhough it is just a hello world printf statement.
Then those programs included it unnecessarily.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks guys for your help and comments. Really appreciate it.
|
|
|
|
|
Hello developers,
Can i define a class in header file and declare it in .cpp file if using template or do i have to define and declare in the same header file. I have got two classes so do i have to define and declare both in the same header file or is it possible to have different header file for both classes.
I am writing double linked list application. Now i have got two class LList and Node. Now when i simply use template and write the two classes under one file without defining it , then it works perfectly fine but when i try to define the two class seperately i am getting many errors. What should i do in this case ?
Any way out ?
ThankYou
|
|
|
|
|
When you split the two classes into two header files, did
you remember to #include the dependent header file in the one
that depends on it?
If these are template classes, there shouldn't be any code in
CPP files. Actual intances of the template class aren't created
until an object of the class is defined, so at that point the compiler
would need to see the code in the CPP file.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks,
yes i included the dependent header file but i got many errors. But when include the node class declaration and defintion and llist class declartion in one header file then the program works. But yes if i try to declare the llist class first and then define it, it gives me many error.
So i came to the conclusion that i have included all the code under one header file. Declaring template node class and then defining all the functions and then directly defining the template llist class as it doesn't work when i first declare it and then define it.
I guess that each template class could be placed in different header file to use by main method. But in my case it's not working. So i have only main class and the one header file containing two template class.
|
|
|
|
|
If the list class references the node class then the node
class will always have to be defined before (in compile order)
the list class, whether you use separate header files or not.
The following is no different than using a single header file for
both classes...
#pragma once
...define node class...
#pragma once
#include "node.h"
...define list class...
#pragma once
#include "list.h"
...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Hi,
I have a loop in a C++ program which is constantly checking for input from a network source, but I also want to check if the user has entered something into the console - such as a command to stop the program. Obviously I cannot use just standard cin << strCommand;, since that would block until something is entered. Is there any way for me to check if the console has received input?
Regards,
Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
you can use the _kbhit() function. This function returns a nonzero value if a key has been pressed.
|
|
|
|
|
Thanks, exactly what I need!
Regards,
Daníel
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Hi all,
What is the easiest way to convert a CString into a standard C++ sting.
Thanks
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: ...a standard C++ sting
An array of characters?
CString CStr = ...;
LPTSTR pTCharStr = new TCHAR[CStr.GetLength() + 1];
_tcscpy_s(pTCharStr, CStr.GetLength() + 1, CStr);
Or an STL string?
#include <string>
...
CString CStr = ...;
#if defined(_UNICODE)
wstring stdstr = CStr;
#else
string stdstr = CStr;
#endif
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
How about this way,
std::string strRTF(ss.GetString());
ss is the CString.
But, when I use
cout << strRTF;
I got the following compiled error.
binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
What can be the issue.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: How about this way,
std::string strRTF(ss.GetString());
That's fine - what does GetString() return? If it's a CString, then
the only thing I don't like is CString is a generic (template) type
and std::string is not. The code won't be portable to Unicode builds.
This is maybe better in that case...
typedef std::basic_string<tchar> tstring;
...
tstring strRTF(ss.GetString());
Eranga Thennakoon wrote: But, when I use
cout << strRTF;
How about:
cout << strRTF.c_str();
Mark
Mark Salsbery
Microsoft MVP - Visual C++
modified on Thursday, December 13, 2007 10:35:25 PM
|
|
|
|
|
Mark Salsbery wrote: what does GetString() return?
It return a string, standard string.
Mark Salsbery wrote: c_str()
You are right, I have to null-terminated the string.
I appreciate your help all the time...
Eranga
|
|
|
|
|
I have two applications running on one computer. The first app imports data from elsewhere, parses it, and writes out several files using CreateFile and WriteFile to a directory. The second app reads each of these files from the first app using FindFirstFile, CreateFile and ReadFile, and does further processing.
The data written to these files is fairly big in each case (~8 MB), so each file write can take 2-3 seconds. Also, each batch of files can potentially be large (say 100 or more). So, while the first app is busy writing each file, the second app should be able to take the first file it finds (via FindFirstFile), and open and read it. The problem is, ReadFile doesn't return for that first file until the first app has written out ALL of its files. So this ReadFile call in essence hangs for a few minutes, possibly causing havoc elsewhere in the app.
I'm closing my file handles properly in the first app (at least I think I am), so there shouldn't be any reason for ReadFile to wait on file writes that are on different files in the same directory. Is there some "feature" in the Win32 file API that would explain this behavior? I'm writing the files using FILE_FLAG_SEQUENTIAL_SCAN and sharing disabled, if it matters; I've also played with FILE_FLAG_NO_BUFFERING to attempt to improve performance.
|
|
|
|
|
When writing, are you using the CreateFile() and CloseHandle() pair for each file before
moving on to the next file?
Also, I'm pretty sure the files will be found with FindFirstFile() before they are closed
(they show up in explorer while being written ).
Does the reader take this into account, possibly looking for a failure to open due to no shared access?
Mark
|
|
|
|
|
Wouldn't it be easier for the first application to just send a simple message to the second application telling it that file X is finished? Otherwise, FindFirstFile() is going to find files that exist but are empty or locked.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You better write the files one by one with *.tmp extension and when ready rename it. This makes sure that only ready files are found.
Greetings from Germany
|
|
|
|
|
Hello
I want to work with files unmanaged.
I've been using fstream for file i/o but the problem is that if the file is greater than the maximum value of long I am not able to seek within it since the offset in the seek command doesn't accept values greater than long.
Is there any other way I should work with files ? (unmanaged, not using system.dll)
Clint
|
|
|
|
|
|
Has Windows Vista got graphics routines to read from JPG images to internal image mode, and to output from internal image mode into JPG mode? If so, how does Visual C++ call those routines?
|
|
|
|
|
GDI+[^] wll handle JPEGs plus several other types.
It's included on XP+ operating systems and available as a redistributable for versions
back to Windows 98.
If you use the CImage class[^], which uses GDI+ to load and save images,
you can load and save images with just a couple lines of code.
You can also look at the CImage class source code to see how it uses GDI+.
Mark
|
|
|
|