| | |
wide character file streams
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2007
Posts: 28
Reputation:
Solved Threads: 0
I'm trying to read a Unicode file using std::wifstream. On wintel.
And this is my output
Now the spaces between each character and the '■' thing at the start arn't in the text file. What am I doing wrong?
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { wifstream File("input.txt"); wstring Line; while(!File.eof() ) { getline(File, Line); wcout << Line << endl; } system("pause"); return 0; }
And this is my output
C++ Syntax (Toggle Plain Text)
■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 e n t e n c e . 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.
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.
•
•
Join Date: Oct 2008
Posts: 40
Reputation:
Solved Threads: 6
•
•
•
•
I'm trying to read a Unicode file using std::wifstream. On wintel.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { wifstream File("input.txt"); wstring Line; while(!File.eof() ) { getline(File, Line); wcout << Line << endl; } system("pause"); return 0; }
And this is my output
C++ Syntax (Toggle Plain Text)
■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 e n t e n c e . 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?
C++ Syntax (Toggle Plain Text)
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
![]() |
Other Threads in the C++ Forum
- Previous Thread: Need Help Rounding Off
- Next Thread: Eclipse for Java developers made to do C++
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class code coding compile console conversion count data database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






