help - writing text to a file

H

hamishd

I have some texts files, which i want to read in each line, and then
write back each line to a new text file.

So for example, I want to read in the 2 lines below:

"C:\Data\ÓêÒ¹ÐÇ¿Õ",6,10,3,3,8
"",0,0,0,318.592,83.04552

I store each line of data in the following vector:

std::vector<CString> FileData;

So FileData[0] = ""C:\Data\ÓêÒ¹ÐÇ¿Õ",6,10,3,3,8"
FileData[1] = """,0,0,0,318.592,83.04552"

(the data is in the vector correctly)
Then I go to write the data to a new text file...

FILE * stream;
stream = _wfopen(filename, _T("w"));
for(j=0;j<FileData.size();j++)
fwprintf(stream, _T("%s"), FileData[j]);
fclose(stream);

However, when I look at the text file, it's gone wrong:
C:\Data\,0,0,0,318.592,83.0455

I'm doing this in unicode. Is there any obvious problem?
 
R

red floyd

hamishd said:
I have some texts files, which i want to read in each line, and then
write back each line to a new text file.

So for example, I want to read in the 2 lines below:

"C:\Data\ÓêÒ¹ÐÇ¿Õ",6,10,3,3,8
"",0,0,0,318.592,83.04552

I store each line of data in the following vector:

std::vector<CString> FileData;

So FileData[0] = ""C:\Data\ÓêÒ¹ÐÇ¿Õ",6,10,3,3,8"
FileData[1] = """,0,0,0,318.592,83.04552"

(the data is in the vector correctly)
Then I go to write the data to a new text file...

FILE * stream;
stream = _wfopen(filename, _T("w"));
for(j=0;j<FileData.size();j++)
fwprintf(stream, _T("%s"), FileData[j]);
fclose(stream);

However, when I look at the text file, it's gone wrong:
C:\Data\,0,0,0,318.592,83.0455

I'm doing this in unicode. Is there any obvious problem?

Other than std::vector, FILE and fclose, none of this appears to be
Standard C++.

May I suggest you ask in an MFC group?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,297
Messages
2,571,536
Members
48,282
Latest member
Xyprime

Latest Threads

Top