How do you call inputted information to another line?

I just want to know how to put inputted information into a std::cout line? The bottom line with the hyphens around it is where I am stuck. When somebody puts their name in, I would like the line afterwards to essentially copy what they inputted, to create the illusion that the program understands them. If anyone could shed some light it'd be appreciated..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//test3

#include <iostream>

int main ()

{
	int name;
	std::cout << "Welcome to Carion.\n";
	std::cout << "What is your name:";
	std::cin >> name;
	std::cout << "So your name is...\n";
	- std::cout << std::cin "name"; -
}
Your name variable should be of type std::string. All you need to do is std::cout << name;
Integers cannot hold names. Here is a working example of what you want to do:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>

int main ()

{
	std::string name; // Integers cannot hold names
	std::cout << "Welcome to Carion.\n";
	std::cout << "What is your name:";
	std::getline(std::cin, name); // Get the whole line instead of a single word
	std::cout << "So your name is...\n";
	std::cout << name << "\n";
}
Last edited on
Topic archived. No new replies allowed.