DrakaSAN DrakaSAN - 1 year ago 86
C++ Question

Can t see the output of my c++ program (debian)

This might be a dumb question but...

I am programming some stuff in C++, it compile well on g++, but when I start the binary, there is nothing printed, even if I redirect the output in a file.


#include <iostream>
using namespace std;


int main ()
//Table tab;
//tab.setc(1, 1, 'c');
//tab.setc(10, 5, 'd');
cout << "print" << endl;
cout << "end" << endl;
return 0;

In shell:

>g++ print.cpp -o print
>print > t
>cat t

Is it a problem in my code, or do I start my program in the wrong way?

Answer Source

If you just call

> print

you are actually executing /usr/bin/print, that from the man page is

run-mailcap, view, see, edit, compose, print - execute programs via entries in the mailcap file

Tu run your code you should do one of these three things:

  1. If from the same directory

    > ./print
  2. From an other directory

    > /path/to/exe/print
  3. Add the directory where the exe live (/path/to/exe/) in the PATH before /usr/bin

    > export PATH=/path/to/exe:$PATH
    > print

    If you want to add it permanently, just add export PATH=/path/to/exe:$PATH to you ~/.profile file

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download