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 -
#include <iostream>
-
-
int main(){
-
std::cout << "Hello C++ World!";
-
return 0;
-
}
-
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 -
#include <iostream>
-
-
int main(){
-
std::cout << "Hello C++ World!" << std::endl;
-
return 0;
-
}
-
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?
Include the statement
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, - int x;
-
cout << "Enter an integer: "; // No endl, but still displays
-
cin >> x; // DIsplay is "Enter an integer: (User input here)"
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.
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.
anyone else can help with this?
please.
Nicky Eng
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
}
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
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:
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?
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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 =...
|
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?
...
|
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...
|
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,...
|
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"...
|
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...
|
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...
|
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...
|
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:
<%@...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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...
|
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...
| |