C++ 读取中文文本 ifstream
2015-03-05 16:57
3047 查看
#include <Windows.h> #include <iostream> #include <fstream> #include <stdio.h> #include <string> using namespace std; int main() { string str = ""; wchar_t wch = '中'; char ch = 'b'; cout<<"char : "<<ch<<wch<<endl; char filename[MAX_PATH]; GetModuleFileName(NULL,filename, MAX_PATH); str = (string)filename; int pos = str.find_last_of('\\',str.length()); str = str.substr(0,pos); char * ch2 = const_cast<char *>(str.c_str()); cout<<"file path: "<< ch2<<endl; str += "\\read.txt"; ifstream ifs; ifs.open(str); if (!ifs.is_open()) { cout<<"open file "<<str<<" failed"<<endl; } else { string con = ""; int count = 0; getline(ifs,con,':'); while (ifs) { ++count; cout<<count<<": "<<con<<endl; getline(ifs,con,':'); } cout<<"Done!"<<endl; } system("pause"); return 0; }
相关文章推荐
- vc中ifstream ofstream不能读取带有中文路径
- C++中string类及文件流类(ofstream,ifstream)的基本操作---按行读取文档
- C++读取写入.txt文件(ifstream/ofstream)—读取指定行,修改指定行,复制文件,清除文件,统计文件行数
- C++读取写入.txt文件(ifstream/ofstream)—读取指定行,修改指定行,复制文件,清除文件,统计文件行数
- VC中ifstream中文路径读取失败的问题
- ifStream读取ANSI/Unicode/Utf8文本保存到string里并转成gbk编码
- c++使用getline和ifstream读取文件
- c++中ifstream一次读取整个文件
- c++中ifstream一次读取整个文件
- c++中ifstream一次读取整个文件
- c++使用getline和ifstream读取文件
- c++中ifstream一次读取整个文件
- 转自【北漂民工】C++文件读取操作的全部函数讲解fstream(ofstream/ifstream)
- vc中ifstream ofstream不能读取带有中文路径
- c++中ifstream一次读取整个文件
- C++ 读取中文文本 。。。。
- VC与DEV编译器关于ifstream的文本反复读取问题存在的不同
- c++中ifstream一次读取整个文件
- C++中利用文件输入对象(即ifstream对象)来读取文本文件中带空格的字符串以及混合输入数字与字符串
- c++ std::ifstream 读取文件不完整? 是不是忘记了ios_base::binary