473,385 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1943
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: John | last post by:
Hello all, I am trying to read in lines into a buffer from a file. Normally I would do this very low-level, but I have come to the conclusion I must stop doing everything the hard way. So, I...
7
by: Shane | last post by:
Hi, Thanks in advance for the help. I have been to many websites and tried several solutions to my problem, but have fixed part of it. It's time to come humbly to the newsgroups for help :-) ...
4
by: Eric Boutin | last post by:
Hi all ! I'm currently writing a function that evaluate if there is a diffence beetween 2 streams (istringstream and ifstream). The problem is, it doesn't work. It *always* finds a difference...
5
by: allspamgoeshere3 | last post by:
Hi! I'm having trouble reading text lines from a file describing the levels for a simple game I'm creating. Inside the function that reads the content of the file there is a loop that basically...
2
by: Assertor | last post by:
Hi, All. (VC++6.0) I found some strange thins when using getline() and seekg() of std::ifstream. After the file position of an open file was shift to the end of the file, seekg() did not...
2
by: Bit Byter | last post by:
I have a method in a class implemented like this: int foo (const char* filename, bool flg) { FILE *fp; char *buffer, *tokstr, *tmp; size_t size, toksize; unsigned int i; if ((fp =...
18
by: vermarajeev | last post by:
Hello everybody, This is my second query in this post. Firstly thankx to Banfa, for helping me solve my first query. Here is the code which I have written. #include<iostream>...
6
by: ankit.kumar.agarwal | last post by:
I am facing a problem with getline I am reading a text file with a getline function the lines can have '|' as separator. everything works OK but in case if i have 2 delimitors in file '234||...
8
by: sabby | last post by:
I want to use the getline() so that i can enter a entire name in on line. (with spaces) The prob is that i am initializing the variable as "N/A" and saving it to a text file. it is declared as a...
4
by: hirsh.dan | last post by:
i have a functions that writes information to a file. inside that function i have a line in which i call another function. if this line is executed, nothing is written to the file, but if i remark...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.