我在尝试读取一个文本文件,但是没有任何输出。我觉得可能是它没有正确地链接到我的Visual Studio资源文件夹,但如果我双击它,它可以在Visual Studio中正常打开,并且如果我测试它是否打开或是否好,它不会遇到任何问题。目前程序编译良好,但没有输出。我的命令提示符上面没有任何内容打印出来。有什么建议吗?
代码:
代码:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
char str[100];
ifstream test;
test.open("test.txt");
while(test.getline(str, 100, '#'))
{
cout << str << endl;
}
test.close();
return 0;
}
文本文件
This is a test Textfile#Read more lines here#and here
return 0;
语句上设置一个断点以查看一些输出,或者在return 0;
之前添加类似于system("PAUSE");
或cin.get()
的内容。 - Mr.C64std::string
更安全。string str; while (getline(test, str, '#')) {}
- Geoff Monteetext.txt
文件,它仍然会打开它吗?我的text.txt
文件与我的解决方案在同一个文件夹中。 - Howdy_McGee