【发布时间】:2011-04-23 08:08:45
【问题描述】:
为什么 cin.getline 在正文输入的第二行开始工作,但在第一行中断?
示例程序运行:
Enter name: Will
Enter body: hello world
hello again <= It accepts this one
char* name = new char[100];
char* body = new char[500];
std::cout << "Enter name: ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cin.getline(name, 100);
std::cout << "Enter body: ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cin.getline(body, 500');
std::cin >> body;
【问题讨论】:
-
你的意思是它不起作用?