Input a string in an array by asking the user?

the topic title pretty much sums it up how do i ask the user to write a name and put it inside a array as an string? might sound pretty easy but i really cant think of a way to do it. I can assign a string to an array when im writing the code but how do i input a string entered by a "user" in an array? i.e. while the program is running. help would be appreciated.
What you're looking for is the function "cin", found in <iostream>.

1
2
3
4
5
6
7
8
#include <string>
#include <iostream>
using namespace std;

string name;
cout << "Please enter a name: ";
cin >> name; // Waits for user input, then saves to "name".
cout << "Your name is " << name << "!";
worked thanks for the help. that was easy.. lol tho i know what cin was i just didn't know how to create that "array" of type string.
Last edited on
Topic archived. No new replies allowed.