Created
January 22, 2012 04:58
-
-
Save mahmoudhossam/1655675 to your computer and use it in GitHub Desktop.
Storing user input as strings in a vector.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <iostream> | |
#include <vector> | |
#include <string> | |
int main() | |
{ | |
std::string input = "crap"; | |
std::vector<std::string> storage; | |
while( input != "" ) | |
{ | |
std::cout << "\n\nEnter something: "; | |
std::getline(std::cin, input, '\n'); | |
storage.push_back(input); | |
std::cout << "We now have: ["; | |
for(int i = 0; i < storage.size(); i++) | |
{ | |
if(i == storage.size() - 1) | |
{ | |
std::cout << storage[i]; | |
} else | |
{ | |
std::cout << storage[i] << ", "; | |
} | |
} | |
std::cout << "]"; | |
} | |
// prevents the console window from going away at the end of execution. | |
std::getchar(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment