I am trying to read file which has multiple delimiters per line. Below is the data
2,22:11
3,33:11
4,44:11
5,55:11
6,66:11
7,77:11
8,88:11
9,99:11
10,00:11
11,011:11
12,022:11
13,033:11
14,044:11
15,055:11
16,066:11
17,077:11
18,088:11
19,099:11
And the code is below
Here, Iam trying to read the line first with comma as delimiter to get line and then :
int main() {
std::string line;
std::string token;
size_t isColon;
ifstream infile;
infile.open("/Users/tejas/Documents/Data.txt");
while (std::getline(infile, line,',')) {
cout << line<< endl ;
while(getline(infile, token, ':'))
{
cout<<" : "<<token;
}
}
}
But there is an issue with the code as it is skipping the first line Also if i comment the second while loop,only the first line is getting printed, and below is the output
Ian unable to figure out where exactly the code has gone wrong
Output
2
: 22 : 11
3,33 : 11
4,44 : 11
5,55 : 11
6,66 : 11
7,77 : 11
8,88 : 11
9,99 : 11
10,00 : 11
11,011 : 11
12,022 : 11
13,033 : 11
14,044 : 11
15,055 : 11
16,066 : 11
17,077 : 11
18,088 : 11
19,099 : 11
Aucun commentaire:
Enregistrer un commentaire