C++ help

NSenforcer

Junior Member
Apr 25, 2002
4
0
0
this may sound like a stupid quesiton to all you guru's out tehre but i am in highschool and i need to know what the code is that lets a user enter a string of charcters without using and array or some such structure.. i dont know how and neither does my teacher i jstu want to know if there is a way to have 1 variable represent an entire name, not jstu a letter... thanx
 

PCHPlayer

Golden Member
Oct 9, 2001
1,053
0
0
#include <iostream>

main(int argc, char *argv[])
{
std::string name;

std::cout << "Enter your name: ";
std::cin >> name;

std::cout << "Your name is " << name << std::endl;

}
 

Vadatajs

Diamond Member
Aug 28, 2001
3,475
0
0
I would use a string variable.

#include <iostream>
#include <string>
using namespace std;

int main()
{
string foo;
cout << "Please enter a name: ";
cin >> foo;
cout << "The name you have entered is: " << foo << endl;

return 0;
}

I don't know if your teacher would allow you to use a string or not, but it is probably the best thing for what you want to do.