I thought this would be pretty simple but Windows keeps giving me this message "This application has requested the Runtime to terminate it in an unusal way." Why is this happening?
Note: At frist I wrote the split function by myself, but when that didn't work, i took one straight from my book, so i can't imagine it being wrong. maybe it's in my main() function?
Code:
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using std::cout;
using std::cin;
using std::string;
using std::vector;
using std::endl;
vector<string> split( const string& s ){
vector<string> ret;
typedef string::size_type string_size;
string_size i = 0;
while ( i != s.size() ){
while ( i != s.size() && isspace(s[i]))
i++;
string_size j = i;
while ( j != s.size() && !isspace(s[j]))
j++;
if ( i != j ){
ret.push_back(s.substr(i, j - i));
}
}
return ret;
}
int main(){
cout << "Enter a sentence: " << endl;
string v;
cin >> v;
vector<string> sen = split(v);
cout << "The words in the sentence are: " << endl;
vector<string>::size_type i = 0;
while ( i != sen.size() ){
cout << sen[i] << endl;
i++;
}
}
EDIT: Problem solved. There was something wrong with the program's logic that i completely overlooked.