c++ - Error with reading file in Linux -
in program, take 2 file names command line arguments using following code:
ifstream routesfile (arv[1]); ifstream citiesfile (arv[2]);
i proceed read through file , grab data. both files csvs:
while(citiesfile.good()){ string city; string country; string xstring; string ystring; getline(citiesfile, country, ','); getline(citiesfile, city, ','); getline(citiesfile, xstring, ','); getline(citiesfile, ystring); ... }
when in visual studio using hard-coded file names, works fine. when use command line argument in linux after using g++, can open files correctly after has lot of errors. test file reading, printed out of read values resulted in
terminate called after throwing instance of 'std::out_of_range' what(): map::at hereelf Òœc½Å¹jn!ýô (eÕl˜c
the appearance of here
due being printed in program. doesn't arise error, manually printed test code.
it seems not able read data correctly. in file citiesfile, there 4 values per line, each separated single command, no spaces, , new line character separates lines in file. said above, works fine in visual studio don't think it's problem actual data, reading it.
linux , window has different new line symbol. linux '\n', windows '\r\n'. if copied file linux, need handle these in program. can @ mixing cin , getline under linux , windows reference.
Comments
Post a Comment