wierd getline behaviour
hi,
I don' know what is going wrong with my code. here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <string>
#include <set>
#include <vector>
#include <iterator>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <fstream>
using namespace std;
int main()
{
ifstream fileIO;
fileIO.open("r", ios::in);
if(!fileIO)
{
cerr<<"the file could not be opened "<<endl;
exit(1);
}
std::string data;
getline(fileIO, data); //ignore the first line of th file
getline(fileIO, data);
std::string delims = "|";
std::vector<std::string> line_parts;
boost::split(line_parts, data, boost::is_any_of(delims));
std::copy(
line_parts.begin(),
line_parts.end(),
std::ostream_iterator<std::string>(std::cout, "/")
);
// output: `Please/ split/this/string/`
}
|
the contents of file "r" are
account_number:int|balance:float|branch:string
1001|24000.5|Kukatpally
2004|56010.0|Andheri
1008|2000|Koramanagala
1055|3050|Hauz Khas
output on my system:
/
I don't know where I am going wrong. I have also tried to play with iterators for printing bur that too does not work.
Last edited on
Topic archived. No new replies allowed.