linux 中文输出
#include <stdio.h> 2 #include <stdlib.h> 3 #include <string> 4 #include <fstream> 5 #include <sstream> 6 #include <iostream> 7 #include <iomanip> 8 9 int main() 10 { 11 std::basic_ifstream<wchar_t, std::char_traits<wchar_t> > fs("./test.txt"); 12 if ( fs.fail() ) 13 { 14 printf("Cannot open , errno !\n"); 15 return -1; 16 } 17 //std::locale lc("zh_CN.UTF-8"); 18 std::locale lc(""); 19 std::locale::global(lc); 20 fs.imbue(lc); 21 wchar_t line[256]; 22 23 while ( !fs.eof() ) 24 { 25 line[0] = 0; 26 fs.getline(line, sizeof(line)); 27 std::wcout<<"content: "<<line<<std::endl; 28 printf("\n---> %ls ,%d eof:%d \n", line,sizeof(wchar_t), fs.eof()); 29 } 30 31 printf("press any key to continue.\n"); 32 getchar(); 33 34 return 0; 35 }