0

I have been working on the following piece of code; It opens an inputfile, reads the input, and now I wish to take that input (stored in a string) and split it by whitespaces; inputting each element into an integer vector.

I understand how to typecast. The problem is in the splitting. How do I do this efficiently? I would like to use a while loop or for loop except I am unable to index the string. I converted the string to constant char so I could index it but now I am unable to compare the value at a point in the string to the expression " " in my if statement. What should I do?

Sidharth Ghoshal
  • 658
  • 9
  • 31
  • Why can't you index the string? What did you try as std::string does have indexing functions – mmmmmm Apr 11 '13 at 14:09
  • Idk Visual Studio flipped out at me when I tried – Sidharth Ghoshal Apr 11 '13 at 14:11
  • First, starting your question with "I have been working on the following piece of code" and subsequently not providing any isn't helpful. Second, perhaps compare against a *single char* `' '` rather than a string literal `" "`, or better still, use `isdigit()` or `isspace()`, or even using a `istrstream` to format them into `int` values. – WhozCraig Apr 11 '13 at 14:14

1 Answers1

0

Compare the current symbol to ' '.

SceLus
  • 1,117
  • 13
  • 18