txt文件格式:
5983
5980
5981
5986
5987
5984
5985
6797
6794
6795
6793
6790
6791
6798
6294
270
271
273
274
275
276
277
2142
3519
3518
3513
3512
3511
.
.
.
代码如下:
#include
#include
#include
#include
using namespace std;
int main()
{
char c1[20];
string buffer;
string str1;
stringstream ss;
ifstream inputFile("C:\Users\liux\Desktop\nodes.txt");
while (getline(inputFile, buffer))
{
ss.clear();
ss.str(buffer);
ss >> str1 ;
strcpy(c1, str1.c_str());
cout << str1 << endl;
}
}
文件里的节点为什么不能全部输出!文件格式是每行一个整数(一个整数代表一个节点,)是不是代码有问题?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
5条回答
- threenewbee 2017-12-13 10:21关注
你是在控制台里面显示么?控制台的缓冲有限,你输出的东西多了,后面的会盖住前面的,默认只能显示最后80行。 但是你的程序没有问题。 你可以用这个命令 x:\>你的程序.exe > c:\1.txt 把控制台的输出重定向到一个文件里,就能看到完整的结果了。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报