wide character file streams

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2007
Posts: 28
Reputation: ganbree is an unknown quantity at this point 
Solved Threads: 0
ganbree ganbree is offline Offline
Light Poster

wide character file streams

 
0
  #1
Feb 16th, 2009
I'm trying to read a Unicode file using std::wifstream. On wintel.

  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. wifstream File("input.txt");
  10. wstring Line;
  11.  
  12. while(!File.eof() )
  13. {
  14. getline(File, Line);
  15.  
  16. wcout << Line << endl;
  17. }
  18. system("pause");
  19. return 0;
  20. }

And this is my output
  1.  ■A s e q u e n c e o f l e x i c o n s t h a t m a k e u p a s
  2. e n t e n c e .
  3. Press any key to continue . . .

Now the spaces between each character and the '■' thing at the start arn't in the text file. What am I doing wrong?
Last edited by ganbree; Feb 16th, 2009 at 7:33 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,407
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1468
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: wide character file streams

 
0
  #2
Feb 16th, 2009
The "thing" at the start is probably a binary character that tells programs the file is UNICODE format -- its called "UNICODE signature". When you click this link scroll down the page until you find the section titled "unicode signature". Please feel free to read the rest of the page too
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 40
Reputation: seanhunt is an unknown quantity at this point 
Solved Threads: 6
seanhunt seanhunt is offline Offline
Light Poster

Re: wide character file streams

 
0
  #3
Feb 18th, 2009
Originally Posted by ganbree View Post
I'm trying to read a Unicode file using std::wifstream. On wintel.

  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. wifstream File("input.txt");
  10. wstring Line;
  11.  
  12. while(!File.eof() )
  13. {
  14. getline(File, Line);
  15.  
  16. wcout << Line << endl;
  17. }
  18. system("pause");
  19. return 0;
  20. }

And this is my output
  1.  ■A s e q u e n c e o f l e x i c o n s t h a t m a k e u p a s
  2. e n t e n c e .
  3. Press any key to continue . . .

Now the spaces between each character and the '■' thing at the start arn't in the text file. What am I doing wrong?
Well, at first blush (I haven't tested it) you may need to specify
  1. getline<wchar_t>( File, Line );

Hope it helps,
Sean
Last edited by Ancient Dragon; Feb 18th, 2009 at 7:27 pm. Reason: corrected code tags
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC