码迷,mamicode.com
首页 > 系统相关 > 详细

linux 中文输出

时间:2017-05-18 16:51:22      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:str   lib   int   glob   cal   traits   key   fstream   man   

#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 }

 

linux 中文输出

标签:str   lib   int   glob   cal   traits   key   fstream   man   

原文地址:http://www.cnblogs.com/iclk/p/6873795.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!