I'm taking in string inputs and I need to read in multiple words from one line and push them into a vector. I can't for the life of me figure out how to split the string whenever there's a space character. I know I need to use the getline() function, but I feel like I've tried everything and I'm stuck.
Here's my code so far. I'm aware that the if/else statement are both doing the same thing.
int main(){
    vector<string> vec;
    string str = "";
    string t = "";
    int i = 0;
    while(getline(cin, str){
        if(str != "STOP"){
            if(str[i] == ' '){
                vec.push_back(str);
            }else{
                vec.push_back(str);
            }
        }else{
            cout << vec.size() << endl;
        }
        i += 1;
    }
}
I can't really use any fancy code, just the basic functions
 
    