I am trying to write a function that takes a string input from a file and then stores the string in a vector.
I think the problem lies in the algorithm to take the input and store it in the vector. I am not sure how that is supposed to be done.
This is my code:
Code:
#include <iostream>#include <fstream>
#include <vector>
using namespace std;
void rdFile(vector<string> svec)
{
string line;
ifstream myFile;
myFile.open("Text.txt");
while (getline(myFile, line))
{
svec.push_back(line);
}
myFile.close();
}
int main()
{
vector<string> svec;
rdFile(svec);
for (auto p = svec.begin(); p != svec.end(); p++)
cout << *p;
return 0;
}
Can you see what is wrong, or help me to achieve the goal of the program?
Any help is appreciated!