Program editor programming c++

View: New views
6 Messages — Rating Filter:   Alert me  

Program editor programming c++

by Lopezio :: Rate this Message:

| View Threaded | Show Only this Message

Hi I use rhide for programming in c++, but i get errors when i compile the program. It works in rhide environment but doesn't work when i compile it. Consider the following example
#include "iostream"
int main(){
printf("olare");
return 0;
}
I get error when compile it with gcc ola.cpp -o ola.exe but it works in rhide environment.
What's the best option editor for programming in cpp and compile with gcc?
Thank you

Re: Program editor programming c++

by Axel Freyn :: Rate this Message:

| View Threaded | Show Only this Message

Hi,
On Thu, May 29, 2008 at 03:08:34AM -0700, Lopezio wrote:
> #include "iostream"
> int main(){
> printf("olare");
> return 0;
> }
> I get error when compile it with gcc ola.cpp -o ola.exe but it works in
> rhide environment.
Well, your example is neither valid C-code, nor valid C++-code:
 - iostream belongs to C++, and not c
 - printf is declared in stdio.h, for C
 - you should use #include <iostream> instead of "iostream". With "", gcc
   searches only in the current directory (and in all directories given given as
   include directories on command line)
 - the filename should end on ".c" instead of ".cpp". ".cpp" is understood as
   C++-code by gcc
 - If you see nothing in the output: add a newlin "\n" to the printf-command
 - If you compile using "gcc", the compiler does not link to the C++-libraries.
   use "g++" instead.
   
If you use (C-version, ola.c)
#include <stdio.h>
int main(){
 printf("olare\n");
 return 0;
}
it should work with  gcc ola.c -o ola.exe. This also works with
g++ ola.c -o ola.exe
or as
gc ola.cpp -o ola.exe
if you want

As C++ version, I would propose (in ola.cpp):
#include <iostream>
int main(){
  std::cout << "olare" << std::endl;
}
with
g++ ola.cpp -o ola.exe


The "best" programming environment depends on what you like - I'm using vim

HTH,

Axel




Re: Program editor programming c++

by Lopezio :: Rate this Message:

| View Threaded | Show Only this Message

Hi
Thank you for your help.I'm a beginer on cpp. I'm programming in windows/dos mode and i get error when i compile the program
#include <iostream>
int main(){
std::cout << "olare" << std::endl;
}
I get error when i compile the program with gcc ola.cpp -o ola.exe
Can you help me?
Thank you
Axel Freyn wrote:
Hi,
On Thu, May 29, 2008 at 03:08:34AM -0700, Lopezio wrote:
> #include "iostream"
> int main(){
> printf("olare");
> return 0;
> }
> I get error when compile it with gcc ola.cpp -o ola.exe but it works in
> rhide environment.
Well, your example is neither valid C-code, nor valid C++-code:
 - iostream belongs to C++, and not c
 - printf is declared in stdio.h, for C
 - you should use #include <iostream> instead of "iostream". With "", gcc
   searches only in the current directory (and in all directories given given as
   include directories on command line)
 - the filename should end on ".c" instead of ".cpp". ".cpp" is understood as
   C++-code by gcc
 - If you see nothing in the output: add a newlin "\n" to the printf-command
 - If you compile using "gcc", the compiler does not link to the C++-libraries.
   use "g++" instead.
   
If you use (C-version, ola.c)
#include <stdio.h>
int main(){
 printf("olare\n");
 return 0;
}
it should work with  gcc ola.c -o ola.exe. This also works with
g++ ola.c -o ola.exe
or as
gc ola.cpp -o ola.exe
if you want

As C++ version, I would propose (in ola.cpp):
#include <iostream>
int main(){
  std::cout << "olare" << std::endl;
}
with
g++ ola.cpp -o ola.exe


The "best" programming environment depends on what you like - I'm using vim

HTH,

Axel



Re: Program editor programming c++

by Jan-Benedict Glaw :: Rate this Message:

| View Threaded | Show Only this Message

On Thu, 2008-05-29 14:04:24 -0700, Lopezio <geral@...> wrote:
> Thank you for your help.I'm a beginer on cpp. I'm programming in windows/dos
> mode and i get error when i compile the program
> #include <iostream>
> int main(){
> std::cout << "olare" << std::endl;
> }
> I get error when i compile the program with gcc ola.cpp -o ola.exe
> Can you help me?

It would have helped if you had the error message included...

But I know what's missing. Remember what was said? The gcc compiler
(being a C compiler that's capable of recognizing and compiling C++
sources) won't include libstdc++ in the linker run. So either add that:

gcc foo.cpp -lstdc++

...or use g++ to compile and link.

MfG, JBG

--
      Jan-Benedict Glaw      jbglaw@...              +49-172-7608481
Signature of:           Ich hatte in letzter Zeit ein bißchen viel Realitycheck.
the second  :               Langsam möchte ich mal wieder weiterträumen können.
                             -- Maximilian Wilhelm (18. Mai 2006, #lug-owl.de)


signature.asc (196 bytes) Download Attachment

Re: Program editor programming c++

by Joe Buck :: Rate this Message:

| View Threaded | Show Only this Message

On Thu, May 29, 2008 at 02:04:24PM -0700, Lopezio wrote:
> Hi
> Thank you for your help.I'm a beginer on cpp. I'm programming in windows/dos
> mode and i get error when i compile the program
> #include <iostream>
> int main(){
> std::cout << "olare" << std::endl;
> }
> I get error when i compile the program with gcc ola.cpp -o ola.exe
> Can you help me?

This list is where the developers of gcc communicate; it is not for
user questions.  Please use gcc-help.  And on that list, please don't
say "I get error".  Include the exact error message that you got.

Re: Program editor programming c++

by Lopezio :: Rate this Message:

| View Threaded | Show Only this Message

Thank you guys
g++ solved my problem

Jan-Benedict Glaw wrote:
On Thu, 2008-05-29 14:04:24 -0700, Lopezio <geral@mariolopes.com> wrote:
> Thank you for your help.I'm a beginer on cpp. I'm programming in windows/dos
> mode and i get error when i compile the program
> #include <iostream>
> int main(){
> std::cout << "olare" << std::endl;
> }
> I get error when i compile the program with gcc ola.cpp -o ola.exe
> Can you help me?

It would have helped if you had the error message included...

But I know what's missing. Remember what was said? The gcc compiler
(being a C compiler that's capable of recognizing and compiling C++
sources) won't include libstdc++ in the linker run. So either add that:

gcc foo.cpp -lstdc++

...or use g++ to compile and link.

MfG, JBG

--
      Jan-Benedict Glaw      jbglaw@lug-owl.de              +49-172-7608481
Signature of:           Ich hatte in letzter Zeit ein bißchen viel Realitycheck.
the second  :               Langsam möchte ich mal wieder weiterträumen können.
                             -- Maximilian Wilhelm (18. Mai 2006, #lug-owl.de)