470,874 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

what is the problem with the getline / file?

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?

May 11 '06 #1
4 1852
kathy wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 11 '06 #2
the file is not generated by myself.

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

May 11 '06 #3
kathy wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 11 '06 #4
"kathy" <yq*****@yahoo.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
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.
May 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by John | last post: by
7 posts views Thread by Shane | last post: by
4 posts views Thread by Eric Boutin | last post: by
5 posts views Thread by allspamgoeshere3 | last post: by
6 posts views Thread by ankit.kumar.agarwal | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.