std :: ifstream数据类型?

时间:2017-07-05 16:11:26

标签: c++ csv ifstream

此程序中的变量“read”需要通过函数传递,我不知道它是什么数据类型。我用http://www.cplusplus.com/reference/fstream/ifstream/ifstream/http://www.cplusplus.com/reference/fstream/ifstream/但是我很难找到任何东西,这是不可能的吗?

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();
}

1 个答案:

答案 0 :(得分:3)

您有ifstream read但功能

string read_function(string line, string read)
                                 // ^------

如果将功能更改为

 string read_function(string line, ifstream & read)
                                 // ^------

read_function然后期望一个流作为第二个参数,而不是字符串。

下一个功能会遇到类似的问题。

评论指出了其他问题。

如果您收到有关类型的错误,请坐下来查看您传递给函数的内容以及它们的期望。