Parsing a string to get numbers

I have the following string:

 
  string test = "20400\nJohn";


And I need only the number 20400. I have been trying to do this for the past hour but I can't come up with a solution. I have tried the following:

1
2
3
4
5
6
  string data;
  stringstream stream(test);

  while (getline(test, data, "\n") {
    cout << data << endl;
  }


I thought this would print out the number and then the name, but I can't get it to compile. Am I using the string stream correctly? Is this even a decent way to approach this problem?
You can use the iaplpha() or isdigit() function in the ctype.h.

http://www.cplusplus.com/reference/cctype/isalpha/

http://www.cplusplus.com/reference/cctype/isdigit/

if you use getline like that you must use '\n' getline reads until a character delimiter not a string delimiter.
Thanks... I changed the "\n" to '\n' and now it works.
Topic archived. No new replies allowed.