I am trying to explode a string in c++ using string operations: // read in user input std::cout << "Please enter operation:\n"; std::cin >> operation; while(operation.empty()){ string::size_type loc = operation.find( " ", 0); cout << "Found space at " << loc << endl; operation.erase(operation.at(loc).size()); } Code (markup): I have looked many places, and size should be an operation for strings, however, I keep getting this error: error C2039: 'size' : is not a member of 'System::SByte' I also tried length (which should be the same thing), similar error. Thanks for any help, Peace,
Check this out please, I hope this is exactly what you need http://www.winapizone.net/tutorials/winapi/functions/explode.php regards
Do you mean collapse instead of explode? erase will remove characters. If you do mean collapse, try: string::size_type loc = operation.find( " ", 0); while(loc != -1){ cout << "Found space at " << loc << endl; operation.erase(loc,1); loc = operation.find( " ", 0); }