gpt4 book ai didi

c++ - 文件处理 C++ 错误

转载 作者:行者123 更新时间:2023-11-28 03:14:40 25 4
gpt4 key购买 nike

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

 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com