473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

SImple c++ program with no output..

254 100+
here is the simple program for all the newbie to C++.

i'm a newbie.

i install cygwin and use g++, i compiled it no problems, but there is no output for the program.
once i compiled it successfully, command just jump out before i run the program.

But i try the other way to run the program and it can display the output :

$ ./testing
Hello C++ World!
$


here is the testing.cpp file
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. int main(){
  4.     std::cout << "Hello C++ World!";
  5.     return 0;
  6. }
  7.  
Nov 20 '06 #1
12 4871
Banfa
9,065 Expert Mod 8TB
You need to output a new line because there is no requirement on stdout to display any characters until it sees a new line or the stream is flushed

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. int main(){
  4.     std::cout << "Hello C++ World!" << std::endl;
  5.     return 0;
  6. }
  7.  
Nov 20 '06 #2
nickyeng
254 100+
there is my cygwin screen :



I have included std::endl to end of that line, but same result as i get b4.
Is it anything to do with my installation of cgywin?
Nov 20 '06 #3
Ganon11
3,652 Expert 2GB
Include the statement

Expand|Select|Wrap|Line Numbers
  1. system("PAUSE");
before your return statement. This will sned a pause command to your system, which displays the message "Press any key to continue . . ." and waits for you to press a key before continuing with the program execution.

Banfa, doesn't cout print whatever is given regardless of the presence of an endl? For example,

Expand|Select|Wrap|Line Numbers
  1. int x;
  2. cout << "Enter an integer: "; // No endl, but still displays
  3. cin >> x; // DIsplay is "Enter an integer: (User input here)"
Nov 20 '06 #4
nickyeng
254 100+
i thought that simple hello program would be run with no problem for all.

but if compile with g++, everything seems like a bit difficult.

I included the system("pause") statement before return statement and after stdcout statement.

after i typed "g++ -o testing testing.cpp", it paused and then still no output display.

the result is same screen with 3rd post i replied.

Regards,
Nicky Eng.
Nov 20 '06 #5
Banfa
9,065 Expert Mod 8TB
Banfa, doesn't cout print whatever is given regardless of the presence of an endl?
It is platform dependent, stdout is not required to display printed text until the output is flush. This happen automatically when a newline is printed.

Notice that it is "not required to" but that it isn't "required not to", i.e. a conforming implementation can output the data if it wishes to it just doesn't have to to achieve conformance.


I have to say I hate cygwin with a vengence, if you want something to run on Windows and *nix then write it in standard C/C++ so that you can compile it for both platforms.

Don't write it for *nix and force using a library and overlay that in my experience only ever complicates the issue and results in several extra man hours of debugging.
Nov 20 '06 #6
nickyeng
254 100+
anyone else can help with this?

please.
Nicky Eng
Nov 20 '06 #7
hi,

actually i think your problem is within library of the compiler that you are using , i suggest that if your just a beginner like me, try to use C++ compiler that will execute that simple program easily.

in your program:

#include <iostream>

int main ()
{
std::cout << "Hello C++ World!"; // you should put <<std:: end1;
return 0; // this program should run in C++
}

or you can type it on the other way like this

#include <iostream>

int main ()
{
cout << "Hello C++ World!";
return 0; // This should also run
}
Nov 21 '06 #8
horace1
1,510 Expert 1GB
there is my cygwin screen :



I have included std::endl to end of that line, but same result as i get b4.
Is it anything to do with my installation of cgywin?
you screen dump does not show a run of the program only compilation. You need to compile and run, e.g.

g++ testing.cpp -o testing
./testing
Nov 21 '06 #9
Banfa
9,065 Expert Mod 8TB
you screen dump does not show a run of the program only compilation. You need to compile and run,
DOH! how could I miss that :rolleyes:
Nov 21 '06 #10
nickyeng
254 100+
you screen dump does not show a run of the program only compilation. You need to compile and run, e.g.

g++ testing.cpp -o testing
./testing

that mean my cgywin got something wrong to make it dump?
Nov 21 '06 #11
nickyeng
254 100+
hi,

actually i think your problem is within library of the compiler that you are using , i suggest that if your just a beginner like me, try to use C++ compiler that will execute that simple program easily.

in your program:

#include <iostream>

int main ()
{
std::cout << "Hello C++ World!"; // you should put <<std:: end1;
return 0; // this program should run in C++
}

or you can type it on the other way like this

#include <iostream>

int main ()
{
cout << "Hello C++ World!";
return 0; // This should also run
}
I have to use g++ compiler in cgywin because my this subject required it.
but thanks for the advice.
Nov 21 '06 #12
horace1
1,510 Expert 1GB
that mean my cgywin got something wrong to make it dump?
when I said screen dump I was talking about the image of the screen in your post

You have onlycompiled the program not ran it, to run it you need to type
./testing

after the g++ testing.cc -o testing
Nov 21 '06 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

38
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser =...
31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
17
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
11
by: Ground21 | last post by:
Hello. I'm new // sorry for my english :) I have to write simple program i c++. But I don't know how to code src - program should know it's name (unit1.exe so the name is "unit1" or "unit1.exe"...
8
by: ianenis.tiryaki | last post by:
well i wrote this code but it doesn't work and shows me bunch of syntax if you can help me out finding them i would appreciate it! the program should do simple calculations and no parenthesis...
1
by: jerry | last post by:
i have written a simple phonebook program,i'll show you some of the codes,the program's head file is member.h . i suppose the head file works well.so i don't post it. here's the clips of main...
3
maxx233
by: maxx233 | last post by:
Hello, I'm developing a simple program to control a video switcher we have via RS232. All the backend control stuff is figured out just fine, the interface is what's giving me problems! I'm...
5
by: sayeo87 | last post by:
Hi, I am quite new to JSP so please forgive me if I ask really simple things... I am trying to run system commands on the server and display the output on a webpage. This is what I've got: <%@...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.