下面的代码运行良好,还会检查用户是否输入了正确数量的项目,但当输入有尾随的空行时,它将失败。
string item1, item2, item3;
while(cin.good) {
//this allows me to both check if user input enough items
//EDIT: and if items are of right type so I can cerr
if (cin >> item1 && cin>> item2 && cin>> item3)
我有以下表达式:[^(\r\n)]*来识别任何不包含\r\n的文本。但是,当文本包含(或)时,则无法识别。
示例:
"I have following expression to recognize any text."将被确认为OK。
"I have following expression (A) to recognize any text."将不被识别。
因此,我想要全文:"I have following expression (A) to recognize any text."