#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;
}
C++ 读取中文文本 ifstream
最新推荐文章于 2024-08-14 22:33:49 发布