I'm having problems on how to pass a line from a stream/getline as a function parameter.
I have a text file that is multiple lines long and my program needs to read the first line of it & send it through the function as a parameter and repeat until all of the file's lines have been read.
I've been trying to mess with the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
main()
ifstream in_file2(DNA_strings);
istringstream iss2(line)
while (getline(in_file, line))
{
string x = decode(map, in_file)
}
Function:
string decode(map<string, string>&map, istringstream &in_file)
{
string line;
cout << line << endl;
}
The error I'm getting says there's an undefined reference in my function. Am I even close to what I'm trying to get done anyway?
You do not need to pass the input file to decode. You are not decoding the entire file... you are just decoding one line.
Therefore the function should take a string instead of a istringstream as the 2nd parameter. The string you want to give it will be a string containing the line.
Then... main can call decode with the line object that it pulled out of the file.
Thanks Disch, I got it to at least compile now! :) However, now I'm being a derp somewhere else.
Changed main to:
1 2 3 4
while(getline(in_file, line))
{
string x = decode(map, line);
}
And changed the function to:
1 2 3 4 5 6
string decode(map<string, string>&map, string &line)
{
cout << line << endl; //Testing if the lines are actually being sent through
cout << &line << endl;
return 0;
}
I'm not getting any output for either of the 2 cout statements, what am I screwing up?