I trying to write a char[256] to a text file. Below is my current work:
fstream ofs;
ofs.open("c:\\myURL.txt");
ofs.write((char*)testDest,256);
ofs.close();
It still does not work.
here is the error:
error C2440: ‘type cast’ : cannot convert from ” to ‘char *’
update:
so far, here is my progress attempt, the code can compile, but when running, my program suddenly terminated.
ofstream stream;
CBar *a;
switch(uMessage) {
case WM_PAINT:
return bar->OnPaint();
case WM_ERASEBKGND:
return 1;
case WM_LBUTTONDOWN: //wira
if (!bar->OnClick(wParam, lParam)) {
stream.open("C:\\myURL.txt");
stream << a->testDest << endl; // if I replace `a->testDest` with "testword" string, my prgrom does not terminated. Why?
return 0;
}
break;
Several things wrong or “not good” in your code:
openfails.writefunctions.This will give you more info if something fails:
My guess is that opening the file failed because you lack proper permissions. The above program will tell you where what fails.
UPDATE: To answer your second question: you do this:
Which creates a pointer but leaves it unitiallized. You then want to dereference it to access its
testDestdata member, which obviously leads to a crash. You need to initialize your pointer (or don’t use a pointer here, I see no reason to):Please read any good tutorial on c++. These are mistakes you make either when you’ve not slept for three days or if you don’t understand the basic concepts of the language.