what is the problem with the getline / file?

K

kathy

I try to read my data file line by line by using the following code:

std::fstream inFile( "data.txt", std::ios::in );
std::string line;

while ( std::getline(inFile, line) != NULL )
{
//some lines show ???.
}

Problem is I can not read some lines. I got ???. My file is txt file.I
use notepad to change some data and it works fine.

What is the problem? I guess some character is not show up in the
notepad but it have some effect on getline. Or may be it it UNICODE or
ASC II code mess up?
 
V

Victor Bazarov

kathy said:
I try to read my data file line by line by using the following code:

std::fstream inFile( "data.txt", std::ios::in );
std::string line;

while ( std::getline(inFile, line) != NULL )
{
//some lines show ???.
}

Problem is I can not read some lines. I got ???. My file is txt file.I
use notepad to change some data and it works fine.

What is the problem? I guess some character is not show up in the
notepad but it have some effect on getline. Or may be it it UNICODE or
ASC II code mess up?

Take a look at your file in a hex editor. In ASCII all codes should be
below 0x7f, IIRC. If you know that your file is double-byte, you might
want to look at wchar_t-based streams and std::wstring. I am no expert
on those either, so see if somebody else chimes in as well.

V
 
K

kathy

the file is not generated by myself.

I guess it might be some ASCII code and some UNICODE. What kind of hex
editor available?
 
V

Victor Bazarov

kathy said:
the file is not generated by myself.

I guess it might be some ASCII code and some UNICODE. What kind of hex
editor available?

I dunno. Ask in a newsgroup for your OS. Or google for it.

V
 
J

Jim Langston

kathy said:
the file is not generated by myself.

I guess it might be some ASCII code and some UNICODE. What kind of hex
editor available?

Try googleing for "hexedit" and your os.
There is a program called Hexedit for the mac and one for windows, not sure
if there is one for linux.
 

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

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top