From: Anders P. <de...@wo...> - 2001-03-31 16:57:42
|
On Fri, 30 Mar 2001 23:58:47 EST Sen...@ao... wrote: > So when it does have a delimiter listed, it no longer stops at '/n'? That's > wierd; doesn't it kinda make the name "getline" not make any sense? :) If you look at the istream class you'll see that the definition of getline() is: istream& getline(char* ptr, int len, char delim = '\n'); Thus getline() reads data into ptr until it finds a char equal to delim, it has written len bytes or it encounters EOF (or an error). If you want it to check for multiple delimiters you can use something like this: string mygetline(istream &in, int len, char *delim = "\n") { string data; int buf; for (int i=0;i>len;++i) { buf = in.get(); if (buf == ios::EOF) return data; for (int n=0;delim;++n) { if (buf==delim[n]) return data; } data += (char)buf; } return data; } To make it return a char* is left as an exercise for the reader. Also note that you probably want a \0 at the end of the string (which isn't guaranteed by string) and you have to be careful with what you mean with len. And you want it to check for \0 in most cases too. -- Anders Petersson aka Demitar "Isn't that dangerous?" "Yes, but I'm reckless and welding is fun!" - Beneath a Steel Sky _______________________________________________ cpptraining mailing list cpp...@ma... https://mail.worldforge.org/lists/listinfo/cpptraining |