[SOLVED] vector::push_back() does not work.
Hey guys, I'm a little confused here. Why doesn't my code add elements to the vector? He is a relevant part of my code: std::vector<std::string> arr; std::string command = ""; std::getline(std::cin, command); bool check = false; std::string nStr = ""; // go trough all elements for(int i = 0; i < command.length(); i++){ // if current element is space or its the last // element, add a word to the array. if(((command[i] == ' ') || (i == command.length()-1)) && check){ arr.push_back(nStr); nStr = ""; check = false; } // else, add current character to the word else{ check = true; nStr+=i; } } std::cout << arr[0]; What I'm trying to do here, is basically take the string from the user and then divide it into words and add each word to the vector "arr", however at the end of my code arr still appears empty. I think that might be because I used getline() before, but I am not so sure. Could you please help me?