为什么我不能用这个打印的文件中的每一行?它什么也没输出。
string line;
ifstream s {"book_list.txt"};
while (getline(s, line)) {
cout << line << endl;
}
我已经包含了fstream,sstream,string,stdio.h,stdlib.h以及我正在使用命名空间std;
答案 0 :(得分:0)
#include<iostream>
#include<fstream>
#include<string>
using namespace std
int main()
{
string line;
ifstream s ("book_list.txt");
if (s.is_open())
{
while ( getline (s,line) )
{
cout << line << endl;
}
s.close(); // Don't forget to close the file
}
else
cout << "Unable to open file";
return 0;
}
我跳起来有帮助。
答案 1 :(得分:-1)
我猜文件不存在。 请查看:
<div><p id="question"></p></div>
<form id="form">
<div><input id="answer" placeholder="Answer .."/></div>
<button>Submit answer</button>
</form>
<div><p id="feedback"></p><div>
或
if(!s.good()) {
// error
}
答案 2 :(得分:-1)
你应该这样做:
ngOnDestroy(): void {
this.changes.disconnect();
}
答案 3 :(得分:-1)
#include <iostream>
#include <fsstream>
using namespace std;
int main()
{
string data;
int counter = 0;
ifstream infile("test_file.txt");
while (!infile.eof()){
getline(infile , data);
counter += 1;
}
cout << "The number of lines is : " << counter << endl;
return 0;
}
答案 4 :(得分:-1)
#include <iostream>
#include <fsstream>
using namespace std;
int main()
{
string info;
int counter = 0;
ifstream file("test_file.txt");
while (!file.eof()){
getline(file , info);
counter += 1;
}
cout << "The number of lines is : " << counter << endl;
return 0;
}