2

I see below messages while compiling an c++ program.

 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>]

I was thinking if I can redirect all these messages to an file and do not see anything on the console. I have tried redirecting stderr messages by

g++ test.cpp 2> xx

But this does not seems to work. I still see everything on the console and nothing inside the file.

halfer
  • 19,824
  • 17
  • 99
  • 186
Hemant Bhargava
  • 3,251
  • 4
  • 24
  • 45

1 Answers1

5

For csh type of shells, do:

g++ test.cpp >& xx

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • Thanks Ted. So, this is shotgun approach to redirect everything. Does not matter if it is stderr, stdout or whatever, whatever is on the console would go to the xx. Is my understanding correct? – Hemant Bhargava May 06 '20 at 08:53
  • @HemantBhargava You are welcome! It redirects `stdout` and `stderr`. If the program somehow opens another stream to your terminal and prints to that, it won't be captured, but that is extremely rare. – Ted Lyngmo May 06 '20 at 08:55
  • Out of curiosity, how do you redirect only stderr in that shell? – Piotr Siupa May 06 '20 at 08:59
  • 1
    @NO_NAME That's a question that has been asked for eternety :-) One has to resort to sorcery. Here's one way: [Redirecting stderr in csh](https://stackoverflow.com/questions/32010883/redirecting-stderr-in-csh) I never use `csh` myself and this is one reason. – Ted Lyngmo May 06 '20 at 09:04