I am trying to open a .txt using a void function named ‘scan’ and a vector called ‘lines' but the console keeps returning blank. The same code ran perfectly on Windows but not on Mac (both with Codeblocks). What went possibly wrong? The .txt file is in the same folder as the whole project.
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
void scan(vector<string> &lines)
{
ifstream fin("mytext.txt");
string str;
while(!fin.eof())
{
getline(fin, str);
lines.push_back(str);
}
}
int main()
{
vector <string> lines;
scan(lines);
for(int i=0; i<lines.size(); i++)
{
cout<<lines[i]<<endl;
}
}