爲什麼cin.getline開始爲身體輸入的第二行工作,但打破了第一行?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;
你是什麼意思它不工作? – 2010-10-10 23:18:17