C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28691
Number of posts: 94711

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Dev-C++ problem Posted by newbie_prgamer on 16 Dec 2002 at 1:35 PM
A long while ago I used to program with and older version of bloodsheds dev-c++ and have come back and downloaded the newest beta version. I seem to have gotten lost some were in the old code syntax, I wrote the old "hello world" program and got 72 bugs. whats wrong with me!!?!...

#include <iostream>
using std::cout;
using std::cin;
int main()

{
cout << "Hello ! This is a console app."
cout << "To create a console, go to Project Options and select"
cout << "\'Win32 Console\'."
cout << "Press q to quit "
cin >> quit;
}
Report
Re: Dev-C++ problem Posted by Federal102 on 16 Dec 2002 at 1:48 PM
: A long while ago I used to program with and older version of bloodsheds dev-c++ and have come back and downloaded the newest beta version. I seem to have gotten lost some were in the old code syntax, I wrote the old "hello world" program and got 72 bugs. whats wrong with me!!?!...
:
: #include <iostream>
: using std::cout;
: using std::cin;
: int main()
:
: {
: cout << "Hello ! This is a console app."
: cout << "To create a console, go to Project Options and select"
: cout << "\'Win32 Console\'."
: cout << "Press q to quit "
: cin >> quit;
: }
:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Not sure if it's a feature of dev-c++ or not (I've never used it), but shouldn't all of your code lines end in a semi colon?

Even with that adjustment, all of your out put will print on one line unless you add some "\n" s

Report
Re: Dev-C++ problem Posted by DB1 on 16 Dec 2002 at 1:51 PM
: A long while ago I used to program with and older version of bloodsheds dev-c++ and have come back and downloaded the newest beta version. I seem to have gotten lost some were in the old code syntax, I wrote the old "hello world" program and got 72 bugs. whats wrong with me!!?!...
:
: #include <iostream>
: using std::cout;
: using std::cin;
: int main()
:
: {
: cout << "Hello ! This is a console app."
: cout << "To create a console, go to Project Options and select"
: cout << "\'Win32 Console\'."
: cout << "Press q to quit "
: cin >> quit;
: }
:

Well I think if your going to use cout like that you need to end each line with a ';'. You also need to declare 'quit' as some type, like 'char *quit;' before you can use it, and you also need a return statement at the end of the function 'return 0;'. Hope this helps.
Report
Re: Dev-C++ problem Posted by newbie_prgamer on 16 Dec 2002 at 2:41 PM
Well, I lost touch with all the basic skills I had so I'm going to start all over again, I made this a little simpler...

#include<iostream>
using std::cout;
int main()
{
cout<<"hello, how are you all?";
}

Now I was wondering what was wrong with this? I know there isn't a return, it's because I can't remember how to write it. Were can I go to get the most up to date lessons? got any good books I should read?
Report
Re: Dev-C++ problem Posted by mrbroph on 16 Dec 2002 at 3:35 PM
This message was edited by mrbroph at 2002-12-16 15:35:18

: Well, I lost touch with all the basic skills I had so I'm going to start all over again, I made this a little simpler...
:
: #include<iostream.h>
: using std::cout;
: void main()
: {
: cout<<"hello, how are you all?";
: }
:
: Now I was wondering what was wrong with this? I know there isn't a return, it's because I can't remember how to write it. Were can I go to get the most up to date lessons? got any good books I should read?
:
You were missing the .h from the header declaration and and if main doesnt need to return a value just use void. As for books it depends how much you know i suppose, i would probably reccomend First Course in C++, Harman and jones. or just get yourself a Samms teach yourself book i find they are pretty handy for the basics. A bit more advanced for the OOP side of things your looking at something like C++ How to Program, Deitel and Deitel. hope this helps


Report
Re: Dev-C++ problem Posted by newbie_prgamer on 16 Dec 2002 at 7:33 PM
Okay I retyped in what you put for the fix and I got five bugs. Maybe it's the compiler that is all screwed up. Here is what I put and the errors that it gave me.

: #include<iostream.h>
: using std::cout;
: void main()
: {
: cout<<"hello, how are you all?";
: }

1)Iosteam.h is no such file or directory
2)Main must return
3)cout undeclared
4)in function int main(...)
5)build error(because of other bugs I assume)
Report
Re: Dev-C++ problem Posted by Darius on 16 Dec 2002 at 9:01 PM
: Okay I retyped in what you put for the fix and I got five bugs. Maybe it's the compiler that is all screwed up. Here is what I put and the errors that it gave me.
:
: : #include<iostream.h>
: : using std::cout;
: : void main()
: : {
: : cout<<"hello, how are you all?";
: : }
:
: 1)Iosteam.h is no such file or directory
: 2)Main must return
: 3)cout undeclared
: 4)in function int main(...)
: 5)build error(because of other bugs I assume)
:
Not very surprising as this
#include<iostream>
using std::cout;
int main()
{
cout<<"hello, how are you all?";
}

is a 100% correct program, and the advice mrbroph gave you was poor. If the program above isn't working then you've likely made a mistake installing or using the IDE. Perhaps you should list the errors you are getting with THIS program. Also, when you list errors list the actual text (copy and paste it), don't abbreviate it.


"We can't do nothing and think someone else will make it right."
-Kyoto Now, Bad Religion

Report
Re: Dev-C++ problem Posted by Darius on 16 Dec 2002 at 9:14 PM
: You were missing the .h from the header declaration and and if main doesnt need to return a value just use void.

Since you seem to be giving this advice a lot, I thought I might as well set you straight about this.

In Standard C++, iostream.h does not exist (same for other "standard" header files, e.g. ctype.h) instead it IS iostream with no .h. All C headers are prefixed with c so stdio.h becomes cstdio, ctype.h becomes cctype. (Consequently there is now cstring, string, and string.h) Most relatively new compilers support this. When you use them you'll need a using declaration. Usually for a small driver program a using namespace std; suffices.

As for main starting with void. That is non-standard C or C++ (to whoie: ignoring freestanding implementations ;). It never was standard (though it was legal in C). Most compilers allow it for backwards compatibility with old programs, however, new programs shouldn't use it. There are only two valid C++ entry points:
int main()
and
int main(int argc, char **argv) //or the equivalent char *argv[]

In Standard C++ if you don't want to return something from main, simply don't. A successful return value will automatically be added if one isn't provided by the user. So the smallest legal C++ program is:
int main(){}

"We can't do nothing and think someone else will make it right."
-Kyoto Now, Bad Religion

Report
Re: Dev-C++ problem Posted by newbie_prgamer on 17 Dec 2002 at 6:10 AM
These are the exact errors, copy and pasted.

21 C:\My Documents\first.cpp:1
iostream.h: No such file or directory.

2 C:\My Documents\first.cpp
`cout' not declared

4 C:\My Documents\first.cpp
`main' must return `int'

C:\My Documents\first.cpp
[Warning] In function `int main(...)':

5 C:\My Documents\first.cpp
`cout' undeclared (first use this function)


[Build Error] (Each undeclared identifier is reported only once


Report
Re: Dev-C++ problem Posted by Federal102 on 17 Dec 2002 at 6:48 AM
: These are the exact errors, copy and pasted.
:
: 21 C:\My Documents\first.cpp:1
: iostream.h: No such file or directory.
:
: 2 C:\My Documents\first.cpp
: `cout' not declared
:
: 4 C:\My Documents\first.cpp
: `main' must return `int'
:
: C:\My Documents\first.cpp
: [Warning] In function `int main(...)':
:
: 5 C:\My Documents\first.cpp
: `cout' undeclared (first use this function)
:
:
: [Build Error] (Each undeclared identifier is reported only once
:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Your problems are as follows:

1. Your compiler cannot find iostream.h
You need to modify your compiler settings for include files to look in the directory where this file is stored, or better still use std::iostream (i.e without the h)

2. std::cout is defined in <iostream>, not <iostream.h>

3. Your compiler is enforcing the more modern style of main function which returns an int rather than void. Just put "return 0" at the end of your main function and you'll be OK. It should look something like


int main()
{
  //code here
  return 0;
}



4. cout as "undeclared" goes back to point 1

The basic problem is that you are trying to include old style header, but use new style std function calls. I'm not sure who told you to do that, but it's just plain wrong.

Hope this helps


Report
Re: Dev-C++ problem Posted by newbie_prgamer on 20 Dec 2002 at 10:50 PM
Your all giveing great advise but It still doesn't seem to work out for me, could some one post this program as it should be written and I'll past it to my compiler and see if I can get it to run?
Report
Re: Dev-C++ problem Posted by DoomDragoon on 31 May 2007 at 7:24 PM
: Your all giveing great advise but It still doesn't seem to work out
: for me, could some one post this program as it should be written and
: I'll past it to my compiler and see if I can get it to run?
:

just copy paste entire code, don't worry about anything after a // it won't affect your program

#include<iostream>
using namespace std; //this needed to be changed
int main()
{
cout<<"hello, how are you all?"<<endl; //a basic end line is added
cin.get(); //waits for user to press enter before closing screen
}
Report
Re: Dev-C++ problem Posted by MT2002 on 31 May 2007 at 8:06 PM

: just copy paste entire code, don't worry about anything after a //
: it won't affect your program
:
: #include<iostream>
: using namespace std; //this needed to be changed
: int main()
: {
: cout<<"hello, how are you all?"<<endl; //a basic end line is added
: cin.get(); //waits for user to press enter before closing screen
: }
:

This thread started more then five years ago.

Please dont bring back dead topics.
Report
Re: Dev-C++ problem Posted by Lundin on 31 May 2007 at 11:33 PM
:
: : just copy paste entire code, don't worry about anything after a //
: : it won't affect your program
: :
: : #include<iostream>
: : using namespace std; //this needed to be changed
: : int main()
: : {
: : cout<<"hello, how are you all?"<<endl; //a basic end line is added
: : cin.get(); //waits for user to press enter before closing screen
: : }
: :
:
: This thread started more then five years ago.
:
: Please dont bring back dead topics.


I'm trying to get the webmaster to lock all old threads. We still don't know if they are brought back because of some technical problem or because of people who don't understand how to use the GUI. Anyway, I'm locking them as they pop up.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.