0
我做了我的简单txt扫描器,他将文本写入与我的选择匹配的文件中。问题是写入文件时,而不是笔写入,例如,洀漀。在照片中可以看到,例如:将Unicode字符串写入一个txt文件
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int offset;
wstring DBSearchLine, ScanLine;
wifstream ScanFile, DBSearchFile;
wofstream ResultFile;
ScanFile.open("ScanFile.txt", ios_base::binary);
ResultFile.open("ResultFile.txt", ios::out, ios_base::binary);
if (ScanFile.is_open())
{
while (!ScanFile.eof())
{
DBSearchFile.open("DBSearchFile.txt", ios_base::binary);
if (!DBSearchFile.is_open())
{
cout << "Error open DBSearchFile.txt" << "\n";
break;
}
getline(ScanFile, ScanLine);
wcout << "Scan line is - " << ScanLine << "\n";
while (!DBSearchFile.eof())
{
getline(DBSearchFile, DBSearchLine);
wcout << "DBSearchLine is -" << DBSearchLine << "\n";
if ((offset = ScanLine.find(DBSearchLine, 0)) != string::npos)
{
ResultFile << ScanLine << L"\n";
}
}
DBSearchFile.close();
}
ScanFile.close();
}
else
{
cout << "Error open ScanFile.txt" << "\n";
}
system("PAUSE");
return 0;
}
请问,如果你使用字符,而不是宽字符工作的呢? – ZDF
@ZDF如果你的意思是字符串是无法使用getline的wstring,因为插入的字符串是wstring。并且在编码方面应该有所不同 – Marek
'ResultFile.open(“ResultFile.txt”,ios :: out,ios_base :: binary)' - 不应该是'ios :: out |的ios_base :: binary'?此外,不能再现 - 铿锵3.9.0,Ubuntu 14.04.05 x86_64。 –