read from a file token by token

how to get characters token by token when we have more than one tokens by using get method.

get ( char* s, streamsize n, char delim )

how can i pass more than one delim as argument to above method.
If you want to lex a file, the easiest way is to read it character by character and building up the tokens yourself.
This way you get full control of what is going on.

If you want more specific help you need to give a more specific explanation of your problem
okay. i will be more clear.

the file to be read:
blabla blabla\nbla

i want to write such a get method that returns blabla, blabla, bla respectively when i call this method three times.

Note:I know, i need to ignore one char every time i use get with e delim char in order to extract and ignore the delim char.
You don't have to tokenize because your tokens are all the same (strings with no meaning). Just ignore whitespace. You can take advantage of operator >>:

1
2
3
4
5
6
std::string f(istream& is)
{
    std::string s;
    is >> s;
    return s;
}

If it returns the empty string, the stream is empty. You could just parse the whole thing at once, since we're not tokenizing:

1
2
3
4
5
std::vector<std::string> strings;
std::string s;
while(stream >> s) {
    strings.push_back(s);
}
Thank you for your reply.

It clearly works. But still i wonder how I can ignore whitespaces by using get method when reading file.
You can only pass that method one character to be a delimiter, so I don't see how you can ignore either ' ' or '\n' in a single call. You could use strtok() ( http://www.cplusplus.com/reference/clibrary/cstring/strtok/ ), which takes a string of delimiters and works much like you requested.
yeah, strtok() is much more suitable for multiple delimiters.

thanks.
Topic archived. No new replies allowed.