-
May 21st, 2012, 03:45 PM
#1
Read Text File - first line has extra char
This should be a trivial excersize, but for some reason I'm getting a problem
when I read a text file. I'm reading a list of strings in text file, with one string per line. The first line has extra characters in the string, the rest of the lines read are fine, and I can't understand where the extra characters come from. Any ideas?
The file format is this...
A
AA
AAN
AAP
AAPL
AAWW
AAXJ
....
...
Code:
std::vector<std::string> strSymbolList;
std::string s = "";
std::ifstream infile( m_strFileSymbols );
while( std::getline(infile, s) )
{
strSymbolList.push_back(s);
}
infile.close();
-
May 21st, 2012, 03:51 PM
#2
Re: Read Text File - first line has extra char
Is your text file UTF-8-encoded?
If yes, the first character is probably the Byte Order Mark.
Read more about it here: http://en.wikipedia.org/wiki/Byte_order_mark
If you want to remove it, save the text file explicitly as ANSI.
-
May 21st, 2012, 03:57 PM
#3
Re: Read Text File - first line has extra char
Originally Posted by TomasRiker
Is your text file UTF-8-encoded?
If yes, the first character is probably the Byte Order Mark.
Read more about it here: http://en.wikipedia.org/wiki/Byte_order_mark
If you want to remove it, save the text file explicitly as ANSI.
Yes that did it. The file was exported from MSSQL and that was the problem.
Thanks.
-
May 21st, 2012, 04:05 PM
#4
Re: Read Text File - first line has extra char
Originally Posted by cbpetro
This should be a trivial excersize, but for some reason I'm getting a problem
when I read a text file. I'm reading a list of strings in text file, with one string per line. The first line has extra characters in the string, the rest of the lines read are fine, and I can't understand where the extra characters come from. Any ideas?
It would help if you attached the actual file you're reading instead of typing in what you think is in the file. The character may be a non-visible control character or some other character that you do not expect.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|