cjxstudent 发表于 2016-05-24 11:18

异常字符求助

手头有个工作需要过滤一个文本文件,但总是被某个异常字符终止了程序,请大神指点,谢谢.
输入的文件:in.txt
"第1行"
"第2行"
"第3行"
"异常行"
"第4行"
"第5行"
源程序
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<cstring>


const int SIZE=500;//文件名长度
int main()
{
using namespace std;
char filename;
//输入模块
ifstream inFile;
cout<<"请输入待处理的文件名,包含路径和后缀名(例如E:\\input.txt):";
cin.getline(filename,SIZE);
inFile.open(filename);


ofstream outFileWrong;
cout<<"请输入错误记录的接收文件名,包含路径和后缀名(例如E:\\output.txt):";
cin.getline(filename,SIZE);
outFileWrong.open(filename);

string str_line;//存放每行记录的对象
while(getline(inFile,str_line))
{
      outFileWrong<<str_line<<endl;
}

outFileWrong.close();
inFile.close();
return 0;
}
得到的文件:out.txt
"第1行"
"第2行"
"第3行"
"
总是被那个向右的箭头终止了程序.

bruceteen 发表于 2016-05-26 08:18

附件无法下载,需要手机扫描然后……

cjxstudent 发表于 2016-05-26 17:24

怎么下载还有这设定的?in文件只有这几行内容,把它贴到记事本就可以了.

"第1行"
"第2行"
"第3行"
"异常行"
"第4行"
"第5行"


bruceteen 发表于 2016-05-27 08:31

在,你的 "异常行" 中,第一个引号和‘异’字之间有个 0x1A 字符。
Google了一下,别人也出过这个问题:http://www.xuebuyuan.com/1321659.html
页: [1]
查看完整版本: 异常字符求助