Skip to content

Instantly share code, notes, and snippets.

@mahmoudhossam
Created January 22, 2012 04:58
Show Gist options
  • Save mahmoudhossam/1655675 to your computer and use it in GitHub Desktop.
Save mahmoudhossam/1655675 to your computer and use it in GitHub Desktop.
Storing user input as strings in a vector.
#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