Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 4.4 C++;使用GCC与LLVM_Xcode_Standard Library_Llvm Clang_Libc++ - Fatal编程技术网

Xcode 4.4 C++;使用GCC与LLVM

Xcode 4.4 C++;使用GCC与LLVM,xcode,standard-library,llvm-clang,libc++,Xcode,Standard Library,Llvm Clang,Libc++,多年来,我一直在使用下面的代码来使用cin上的字符,包括下一个换行符 void skip_rest_of_line() { while (cin.get() != '\n') {} } 我会在捕获异常并清除cin状态后调用此函数,如: catch (Error& error) { cout << error.msg << endl; cin.clear(); skip_rest_of_line(); } 在Xcode的输

多年来,我一直在使用下面的代码来使用cin上的字符,包括下一个换行符

void skip_rest_of_line()
{
    while (cin.get() != '\n') {}
}
我会在捕获异常并清除cin状态后调用此函数,如:

catch (Error& error) {
    cout << error.msg << endl;
    cin.clear();
    skip_rest_of_line();
    }
在Xcode的输出窗口中:

ready for input: 
1 2 3 4 5 
1 2 3 
ready for input: 
6 7 8 3 
6 7 8 3 
done
但是对于C++11,libc++,第一行不会发生任何事情,直到我在两行输入之后输入第二次返回击键,但是正确的丢弃仍然发生。因此,每个输入行后面的额外空间就是第二次击键的样子

ready for input: 
1 2 3 4 5 

1 2 3 
ready for input: 
6 7 8 3 

6 7 8 3 
done
使用上述cin.ignore调用而不是围绕cin.get()的while循环也会发生同样的行为。所以问题是“为什么需要第二次返回击键?”

我认为这是Lion上的libc++中的一个错误,并且修复了Mountain Lion上的错误。但如果没有完整的测试用例,就很难确定

更新


谢谢你的测试用例。确认了Lion上的错误,并修复了Mountain Lion上的错误。

这里有一个测试用例,它可能比必要的更复杂,但做了与我实际代码应该做的相同的事情,即根据读取的内容丢弃cin行的其余部分。这取决于我使用的Xcode 4.4.1编译器和库选项的不同。代码读取并保存整数,但如果读取了3,则会通过换行符丢弃并重复。使用GNU++98 | | GNU++11,libstd++可以像我预期的那样工作,放弃4&5准备输入:1 2 3 4 5 1 2 3准备输入:6 7 8 3 6 7 8 3请不要忽略上面的注释;我发现我必须添加测试用例作为对原始问题的编辑。我是这里的新手!
1 2 3 4 5 
6 7 8 3 
ready for input: 
1 2 3 4 5 
1 2 3 
ready for input: 
6 7 8 3 
6 7 8 3 
done
ready for input: 
1 2 3 4 5 

1 2 3 
ready for input: 
6 7 8 3 

6 7 8 3 
done