Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ std::ifstream数据类型?_C++_Csv_Ifstream - Fatal编程技术网

C++ std::ifstream数据类型?

C++ std::ifstream数据类型?,c++,csv,ifstream,C++,Csv,Ifstream,这个程序中的变量“read”需要通过一个函数传递,我不知道它是什么数据类型。我用过 但我正在努力寻找任何东西,这是不可能的吗 int main() { string line = " ", ans = " ", ans2 = " ", data = " "; int i = 0, j = 0; cout << "What file do you want to read? : "; cin >> ans; cout << "What do you want t

这个程序中的变量“read”需要通过一个函数传递,我不知道它是什么数据类型。我用过 但我正在努力寻找任何东西,这是不可能的吗

int main()
{
string line = " ", ans = " ", ans2 = " ", data = " ";
int i = 0, j = 0;
cout << "What file do you want to read? : ";
cin >> ans;
cout << "What do you want the new file to be called? : ";
cin >> ans2;
ifstream read(ans.c_str());
for (i = 0; !read.eof(); i++)
{
    read_function(line, read);
    write_function(line, ans2);
}
return 0;
}


string read_function(string line, string read)
{
        getline(read, line, ' ');
        cout << line;
}

void write_function(string line, string ans2)
{
    ofstream write(ans2.c_str(), ios::app);
    write << line;
    write.close();
}
intmain()
{
字符串line=“”,ans=“”,ans2=“”,data=“”;
int i=0,j=0;
cout>ans;
cout>ans2;
ifstream read(ans.c_str());
对于(i=0;!read.eof();i++)
{
读取功能(行,读取);
写_函数(行,ans2);
}
返回0;
}
字符串读取函数(字符串行、字符串读取)
{
getline(读取,第行“”);

您是否有
ifstream read
但有一个函数

string read_function(string line, string read)
                                 // ^------
如果将函数更改为

 string read_function(string line, ifstream & read)
                                 // ^------
然后,
read_函数
需要一个流作为第二个参数,而不是字符串

下一个函数也会出现类似的问题

评论指出了其他问题


如果您在类型方面遇到错误,请坐下来看看您传递给函数的内容以及它们的期望值。

您所说的“努力寻找任何东西”是什么意思?它字面上说对象
read
的类型是
ifstream
,而您刚刚链接到了ifstream的引用。问题是什么?我需要通过函数传递变量read,但我不知道它在那里说的是什么数据类型。这是一个troll吗?@doctorlove否如果您有生成错误,请预先发送给你。从来没有听说过,不知道为什么它是如此高度评价在亚马逊上。这里非常感谢你,这是我需要知道的,对不起所有人,我只是开始使用C++,所以我的问题可能对你来说似乎很奇怪。))很高兴有帮助。继续练习。不断问问题。找一两本好书。(看评论中的列表)。也问问你的老板/同事。