I want to process each line of a file, and then split it by a delimiter and get for example first and third token.
In python,
with open("filename.txt") as f:
for line in f:
tokens = line.split("|")
print(tokens[0], tokens[2])
So, cpp, I can read the lines of a file with getline
. Like this:
ifstream fin(f);
string myStr;
while( getline(fin, myStr)){
}
Now, how to split the myStr with |
and get the tokens? I tried to call getline(myStr, token, '|')
inside the while loop again, but it doesn't seem to work. Can someone please help?
Thanks