Omkar Waghe
Omkar Waghe

Reputation: 178

i could not get an output after ./a.out in c++ even in simple hello program

i write the simple hello program.

#include<iostream>
using namespace std;
int main()
{
 cout<<"hello";
}

and I compile the program as g++ hello.cpp and run it as./a.out but could not get output as hello

Upvotes: 0

Views: 78

Answers (2)

erip
erip

Reputation: 16945

You have output.

You just didn't add a newline character. It worked, but you probably saw something like as follows where your normal prompt was:

hello$

If you change std::cout << "hello"; to std::cout << "hello\n";, it'll "work" as expected.

Upvotes: 0

Umamahesh P
Umamahesh P

Reputation: 1244

The sample provide should work and should produce output. I do not see a reason not to print output. You could try flushing the std output stream and see whether it makes any difference. If you are running the program on a Linux platform, then you can debug using strace and there should be a write system call at the end.

strace a.out

Example: .... write(1, "hello", 5hello) = 5

exit_group(0) = ?

Upvotes: 1

Related Questions