linux - 将 g++ 编译器的输出重定向到文件?

标签 linux g++ tcsh

我在编译 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>]

我在想是否可以将所有这些消息重定向到一个文件,并且在控制台上看不到任何内容。我尝试过重定向 stderr 消息

g++ test.cpp 2> xx

但这似乎不起作用。我仍然在控制台上看到所有内容,但文件内什么也没有。

最佳答案

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

g++ test.cpp>&xx

关于linux - 将 g++ 编译器的输出重定向到文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61630516/

相关文章:

c - eventfd_read() 什么时候会阻塞?

php - 如何使用 php 和 mysql 每秒处理数千个请求?

c - 使用 EVIOCSMASK 过滤键码

linux - 在段错误 : Is there a way, 之后检查指针是否仍然有效?

linux - 查看内核 printk 调试消息

java - 为什么在使用 += 将整数连接到字符串时 g++ 不发出警告/错误

shell - 检查文件是否不存在或比 csh 中的另一个文件旧

linux - tcsh 以 ls -l 格式完成

linux - 如何处理别名中的多个输入?

c++ - 为什么这个看起来无效的代码在 g++ 6.0 上编译成功?