是否将g++编译器的输出重定向到文件? < >我在编译C++程序时看到下面的消息。 test.cpp: In function ‘int main()’: test.cpp:950: error: no match for ‘operator<<’ in ‘std::cout << d->Derived::print()’ /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:108: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:117: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]

是否将g++编译器的输出重定向到文件? < >我在编译C++程序时看到下面的消息。 test.cpp: In function ‘int main()’: test.cpp:950: error: no match for ‘operator<<’ in ‘std::cout << d->Derived::print()’ /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:108: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:117: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>],linux,g++,tcsh,Linux,G++,Tcsh,但这似乎不起作用。我仍然可以在控制台上看到所有内容,但在文件中看不到任何内容。对于csh类型的shell,请执行以下操作: g++test.cpp>&xx对于csh类型的外壳,请执行以下操作: g++test.cpp>&xx可能相关:忽略您做这件事的原因,您是否尝试过g++test.cpp>xx?g++可能在标准输出上写入这些消息。或者您可以使用散弹枪方法g++test.cpp&>xx。如果您试图隐藏消息,请说明是否要重定向消息以存储它们。您使用哪个shell?echo$SHELL怎么说?@Te

但这似乎不起作用。我仍然可以在控制台上看到所有内容,但在文件中看不到任何内容。

对于csh类型的shell,请执行以下操作:

g++test.cpp>&xx

对于csh类型的外壳,请执行以下操作:


g++test.cpp>&xx

可能相关:忽略您做这件事的原因,您是否尝试过g++test.cpp>xx?g++可能在标准输出上写入这些消息。或者您可以使用散弹枪方法g++test.cpp&>xx。如果您试图隐藏消息,请说明是否要重定向消息以存储它们。您使用哪个shell?echo$SHELL怎么说?@TedLyngmo,我明白了。你是对的。这就是我所看到的:echo$0 tcsh echo$SHELL/bin/bash可能相关:忽略您这样做的原因,您是否尝试过g++test.cpp>xx?g++可能在标准输出上写入这些消息。或者您可以使用散弹枪方法g++test.cpp&>xx。如果您试图隐藏消息,请说明是否要重定向消息以存储它们。您使用哪个shell?echo$SHELL怎么说?@TedLyngmo,我明白了。你是对的。这就是我看到的:echo$0 tcsh echo$SHELL/bin/bash谢谢Ted。所以,这是一种用散弹枪重定向一切的方法。不管它是stderr、stdout还是其他什么,控制台上的任何东西都会转到xx。我的理解正确吗?@HemantBhargava不客气!它重定向stdout和stderr。如果程序以某种方式打开另一个流到您的终端并打印到该终端,它将不会被捕获,但这是极为罕见的。出于好奇,您如何在该外壳中只重定向stderr?@不,这是一个永恒的问题:-必须求助于魔法。这里有一个方法:我自己从来不使用csh,这是一个原因。谢谢Ted。所以,这是一种用散弹枪重定向一切的方法。不管它是stderr、stdout还是其他什么,控制台上的任何东西都会转到xx。我的理解正确吗?@HemantBhargava不客气!它重定向stdout和stderr。如果程序以某种方式打开另一个流到您的终端并打印到该终端,它将不会被捕获,但这是极为罕见的。出于好奇,您如何在该外壳中只重定向stderr?@不,这是一个永恒的问题:-必须求助于魔法。这里有一个方法:我自己从来不使用csh,这是一个原因。
g++ test.cpp 2> xx