-1

I've searched this website and I have tried most things and they all don't work If anyone knows what I am doing wrong please help, This is my code.

 string getlinetest;
 cout << "What is the string?" << endl;
 cin >> getlinetest;
 getline(cin >> getlinetest);
 cout << getlinetest << endl;
brc-dd
  • 2,351
  • 3
  • 10
  • 25

1 Answers1

2

std::getline is not used as you are trying to use it. (I think you just made a typo by using >> instead of ,.)

You need to call it like this:

std::string getlinetest;
std::cout << "What is the string?" << std::endl;
std::getline(std::cin, getlinetest);
std::cout << getlinetest << std::endl;


PS:

And I don't get any sense behind using cin >> getlinetest; before using getline. If you want to remove preceding whitespaces, then you probably need to use std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); instead of putting a cin statement before.

Check out these threads:

  1. Using getline(cin, s) after cin
  2. Why does std::getline() skip input after a formatted extraction?
  3. cin and getline skipping input
brc-dd
  • 2,351
  • 3
  • 10
  • 25