我想写一个程序,允许用户写一些随机的东西,但是我得到了一个
错误提示

 no matching call to 
which I am not able to figure it out. please Help me.while you are trying to answer to this question, try to be more noob specific.

here is my code

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

int main()
{
    string story;
    ofstream theFile;
 theFile.open("Random.txt");
 while(cin.get(story,5000)!=EOF)
{
    theFile<< story;
}
return 0;
}

最佳答案

带有2个参数的cin.get期望char*作为第一个参数,而您试图将string作为第一个参数。

如果要读取std::string而不是C字符串直到行尾,请使用getline(cin, story)

如果要读取字符串直到下一个空格或换行符或另一个空白符号,请使用cin >> story;

关于c++ - 文件处理C++错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17296494/

10-10 06:58