HELP please: C++ Not working!!

HELP please: C++ Not working!!

Post by RadSurfe » Mon, 21 Jul 2003 10:51:15



Please help so I do not loose any sleep over this!
I'd really like to understand this once and for all ;-)

My program looks like this:

[gcc -dumpversion = 3.23]

/* C++ */

#include <iostream>

int main(void) {

  cout << "Hello World!" << endl;

Quote:}

invokation:

h:\djgpp>gcc -x c++ hw.cpp -o hw.exe
(is this okay?)

Outcome:

hw.cpp: In function `int main()':
hw.cpp:7: `cout' undeclared (first use this function)
hw.cpp:7: (Each undeclared identifier is reported only once for each
function it appears in.)
hw.cpp:7: `endl' undeclared (first use this function)

WHAT is wrong here?

I have   \djgpp\lang\cxx\....     as extracted
I have \djgpp\lib\gcc-lib\...      etc; as extracted
and files from both GCC and GPP archives are carefully
copied over...
why am I still have problems?

Which version of     cxxfilt.exe    is supposed to be in
\DJGPP\bin ?
I have the 1st one encountered in there (prior to GPP).

HELP!

Apparently ordinary 'C' programs are compiling fine.

//RadSurfer//

THANKS!

 
 
 

HELP please: C++ Not working!!

Post by A. Sinan Unu » Mon, 21 Jul 2003 12:06:51




Quote:> Please help so I do not loose any sleep over this!
> I'd really like to understand this once and for all ;-)

> My program looks like this:

> [gcc -dumpversion = 3.23]

> /* C++ */

> #include <iostream>

> int main(void) {

>   cout << "Hello World!" << endl;

> }

> invokation:

> h:\djgpp>gcc -x c++ hw.cpp -o hw.exe
> (is this okay?)

Change that to:

#include <iostream>

int main(void) {
    std::cout << "Hello World!" << std::endl;

Quote:}

and

gxx -Wall hw.cpp -o hw.exe

Quote:> Outcome:

> hw.cpp: In function `int main()':
> hw.cpp:7: `cout' undeclared (first use this function)
> hw.cpp:7: (Each undeclared identifier is reported only once for each
> function it appears in.)
> hw.cpp:7: `endl' undeclared (first use this function)

> WHAT is wrong here?

You need a C++ book that shows standard C++/

Quote:> I have   \djgpp\lang\cxx\....     as extracted
> I have \djgpp\lib\gcc-lib\...      etc; as extracted
> and files from both GCC and GPP archives are carefully
> copied over...

What do you mean 'copied over'?

Sinan.
--
A. Sinan Unur

Remove dashes for address


 
 
 

HELP please: C++ Not working!!

Post by DJ Delori » Mon, 21 Jul 2003 11:42:45


Quote:> #include <iostream>

> int main(void) {

>   cout << "Hello World!" << endl;

> }

#include <iostream>

int main(void) {

  std::cout << "Hello World!" << std::endl;

Quote:}

 
 
 

HELP please: C++ Not working!!

Post by Andrew Cottrel » Mon, 21 Jul 2003 14:17:45


Quote:>My program looks like this:
>/* C++ */

>#include <iostream>

>int main(void) {

>  cout << "Hello World!" << endl;

>}

I suggest that you have a look at one of the newere C++ book as the
C++ standard changed a while ago and the code above is now will not
compile as you have found. You need to add the following line after
the include:-

using namespace std;

Regards,
Andrew

 
 
 

HELP please: C++ Not working!!

Post by Hans-Bernhard Broeke » Tue, 22 Jul 2003 06:48:26



> h:\djgpp>gcc -x c++ hw.cpp -o hw.exe
> (is this okay?)

Sort of.  "gpp" or "gxx" would have been shorter and easier to type than
"gcc -x c++", but other than that, you're fine.

Quote:> WHAT is wrong here?

Your C++ knowledge, and probably also the textbook or tutarial you
learned it from.  ANSI/ISO Standard C++ exists since 1998, and the
source code you showed ignores it completely --- it's ancient
pre-standard C++.  The reason you're observing this now is that
compilers took quite a while to catch up with the language standard
--- for GCC, it took until version 3.0, and even so, it's still not
quite there.  But then, so is hardly any other compiler in the world.
--

Even if all the snow were burnt, ashes would remain.
 
 
 

1. help: worked in turbo c/c++ for dos, but not in djgpp gcc

Hi all;

What is wrong with this code;

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void centertext(char *stri, char *stro)
{
int st, j;
        if(strlen(stri)<=strlen(stro))
                {
                st=((strlen(stro)/2)-(strlen(stri)/2));
                for(j=0; j<strlen(stri); j++) stro[st+j]=stri[j];
                }
    else stro=stri;
    strcpy(stro, "\0");

int main(void)
{
char *name="myc";
char *author="David. E. Goble";
const char *title="Kangaroo Island Pistol Club - Database";
char *date="15th of May, 2002";
char *subtext1="+Program: ";
char *subtext2=" (c) by ";
char *text, *temp;

  strcpy(text, title);

  printf("the value of title is: %s\n", title);
  printf("the value of text is: %s\n\n", text);
  /*
  centertext(title, text);
  */
  printf("the new value of text is %s\n\n", text);

return 0;

2. Flight Of The Amazon Queen

3. Help me please, How can I make work PDCurs22 work with TurboC++3

4. I blew my palmV Charger!!! Now what?

5. help! please, not a newbie q, please read

6. TextOut

7. NEAD HELP PLEASE HELP ME PLEASE PLEASE

8. Micro-emacs replacement strings

9. Outportb for ISA card in Borland C++ does not work!!!!!

10. Mouse not working in DOS but works in Windows

11. HELP - UNDELETE did not work right?

12. Help: Memmaker not work !

13. Mouse not working on DOS program, HELP