-2

The variable "read" in this program needs to be passed through a function and i don't know what data type it is. I have used http://www.cplusplus.com/reference/fstream/ifstream/ifstream/ and http://www.cplusplus.com/reference/fstream/ifstream/ but I'm struggling to find anything, is this just not possible?

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();
}
genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

3

You have ifstream read but a function

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

If you change the function to

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

the read_function then expects a stream as the second parameter, not a string.

You will have a similar problem with the next function.

The comments point out other problems.

If you get an error about types, sit back and look at what you are passing to functions and what they expect.

doctorlove
  • 18,872
  • 2
  • 46
  • 62
  • Thank you so much, this is what i needed to know, Sorry to everyone else i am just starting to use c++ so my question might've seemed odd to you. :) – ToastehMonkey Jul 05 '17 at 16:27
  • Glad to have helped. Keep practising. Keep asking questions. Find one or two good books (look at the list in the comments). Ask you boss/work mates too. – doctorlove Jul 06 '17 at 11:25