Mar 20, 2019 at 7:17am UTC
Following code causes me some problems and I really don't know why:
#include<iostream>
#include<string>
#include <cstring>
#include<cmath>
#include<vector>
#include <fstream>
using namespace std;
int main()
{
string filename = "myfile.csv";
ifstream file (filename);
vector<string> store;
string read;
int q = 0;
if(file.is_open())
{
cout<<"file open"<<endl;
while(getline(file,read,";"))
{
q++;
store.push_back(read);
cout<<read<<endl;
}
for(int i = 0; i<=q; i++)
{
cout<<store[i]<<"i: "<<i<<endl;
}
}
else{cout<<"file not found"<<endl;}
cout<<store[1]<<endl;
return 0;
}
So I try to read a file and seperate it from its semicolons.
I always get the error:
error: no matching function for call to ‘getline(std::__cxx11::string&, std::__cxx11::string&, const char [2])’
Mar 20, 2019 at 8:26am UTC
I see.... Is there a way to work arround this problem or is there a getline() function for strings?
Mar 20, 2019 at 8:54am UTC
Sorry. I thought you meant that a semicolon is not interpreted by the compiler as a char.
Thanks for your help.