getline和 cin

#include <iostream>
#include <string>

int main()
{
  std::string name;
  std::cout << "What is your name? ";
// while( getline (std::cin, name))//遇到换行符当成空格
  
   while((std::cin >> name))//跳过换行符
  std::cout << "Hello, " << name << "!\n";
}

挺好玩的,目前不知道为什么

猜你喜欢

转载自blog.csdn.net/klftespace/article/details/81142564
今日推荐