64,682
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
wchar_t text= L'一';
wcout.imbue(locale( "chs")); //需要设置imbue才能输出中文字符 // set locale to argument
wfstream wfcin;
wfcin.open("r://out.txt", wfstream::in);
wfcin.imbue(locale( "chs"));
for (int ix =0 ; ix !=70000 ; ix++ ) {
wfcin >> text;
wcout << text++;
}
wfcin.close();
return 0;
}
#include <iostream>
#include <fstream>
#include <string>
#include <locale>
using namespace std;
template <size_t N>
inline bool is_valid(const char (&str)[N])
{
for (size_t i=0; i<N-1 && str[i] != 0; ++i)
{
unsigned char ch = str[i];
char szChinese[3] = {0};
if (ch > 0x8E && ch < 0xFF) //中文字符
{
ch = str[i+1];
if (ch >= 0x40 && ch < 0xFF)
{
szChinese[0] = str[i];
szChinese[1] = str[i + 1];
printf("%s\n", szChinese);
++i;
continue;
}
else
{
return false;
}
}
else if (isdigit(str[i]) || isalpha(str[i])) //英文字符 数字
{
printf("%c\n", str[i]);
continue;
}
}
return true;
}
int main()
{
ifstream infile("test.txt");
char line[100];
infile.getline(line, 100);
is_valid(line);
//const char buf[] = "test你好12345";
//is_valid(buf);
infile.close();
system("PAUSE");
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
wchar_t text= L'一';
wcout.imbue(locale( "chs")); //需要设置imbue才能输出中文字符 // set locale to argument
for (int ix =0 ; ix !=70000 ; ix++ )
wcout << text++;
return 0;
}
/*
locale __CLR_OR_THIS_CALL imbue(const locale& _Loc)
{ // set locale to argument
locale _Oldlocale = ios_base::imbue(_Loc);
if (rdbuf() != 0)
rdbuf()->pubimbue(_Loc);
return (_Oldlocale);
}
*/