【发布时间】:2020-07-06 17:28:24
【问题描述】:
我有 2 个空白(保存和加载)。保存文件中的写入并从文件加载负载。问题是当我尝试从该文件中读取时,它只读取一个单词,即使使用 getline。
这是我的代码:
#include <iostream>
#include <windows.h>
#include <limits>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
float r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, puncte, rc1, rc2, rc3, rc4, rc5, rc6, rc7, rc8, rc9, rc10, var;
string q1, q2, q3, q4, q5, q6, q7, q8, q9, q10;
void save()
{
ofstream outfile;
outfile.open("C:\\Users\\Public\\IntrebariTest.txt");
outfile << q1 << " " << q2 << " " << q3 << " " << q4 << q5 << " " << q6 << " " << q7 << " " << q8 << " " << q9 << " " << q10 << rc1 << " " << rc2 << " " << rc3 << " " << rc4 << rc5 << " " << rc6 << " " << rc7 << " " << rc8 << " " << rc9 << " " << rc10;
outfile.close();
}
void load()
{
ifstream infile;
infile.open("C:\\Users\\Public\\IntrebariTest.txt");
infile.getline(cin, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10);
infile >> rc1 >> rc2 >> rc3 >> rc4 >> rc5 >> rc6 >> rc7 >> rc8 >> rc9 >> rc10;
infile.close();
}
因此,如果有人知道导致问题的原因,请发表评论!谢谢! 错误是:
error: no matching function for call to 'std::basic_ifstream<char>::getline(std::istream&, std::__cxx11::string&, std::__cxx11::string&, std::__cxx11::string&, std::__cxx11::string&, std::__cxx11::string&, std::__cxx11::string&, std::__cxx11::string&, std::__cxx11::string&, std::__cxx11::string&, std::__cxx11::string&)'|
【问题讨论】:
-
坦率地说,问题在于您猜测
getline的工作原理。没有需要 11 个参数的重载。您的代码将导致编译器错误,您应该将其包含在问题中 -
我在帖子中添加了错误
-
我认为您使用 getline 错误。此链接可能对您有所帮助:cplusplus.com/doc/tutorial/files
-
你这样做完全错了,因为你应该根据文档来实现它。
标签: c++ codeblocks fstream