在使用ifstream和strtok函数读取text文件内容时出现了问题
text文本内容如下:
一下是本人写的代码:
#include<iostream>
//#include"stdafx.h"
#include <fstream>
#include"string"
using namespace std;
void Readfile()
{
ifstream ifs;
ifs.open("Material Propertity.txt");
if (!ifs.is_open())
{
cout << "打开失败" << endl;
return;
}
char buf[1024] = { 0 };
ifs >> buf;//读取第一行
while (strlen(buf)>0)//buf中有效字符串不为空
{
char *sst = strtok(buf, ":");
if (sst != NULL)
{
sst = strtok(NULL, ":");
//cout << sst << endl;
if (sst != NULL)
{
cout << sst << endl;
}
}
ifs >> buf;//继续读取下一行
}
ifs.close();
}
int main()
{
Readfile();
return 0;
}
当鼠标所在行的代码未注释时,运行出现一下故障:
当改行代码注释后,却运行无结果
求问程序员们这是什么情况?
感谢!