Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

begining c++ programming.


ghost's Avatar
0 0

ok, im ridiculously new to C++ programming every time i try to put together and example, even ones from tutorials it says theres problems in it and it wont compile and run. do i need a diffrent compiler?

#include <iostream.h>

int main() { cout << "Hello World!\n"; return 0; }

even that wont work. and i copied and pasted directly from a site… it says: 1 C:\Dev-Cpp\include\c++\3.4.2\backward\iostream.h:31, from first.cpp In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31, from first.cpp um ok? what?

1 C:\Dev-Cpp\first.cpp from first.cpp

and last 32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

i wouldent mind a programming mentor.


Uber0n's Avatar
Member
0 0

Well that sounds very strange, you should try reinstalling your compiler. And make sure you have the newest version.

Btw you don't have to use <iostream.h> , you can just use <iostream> instead but I don't think that's the cause of the error….

If you need any C++ help you can always PM me B)


ghost's Avatar
0 0

Try adding markupusing namespace std; or markupusing std::cout;

underneath '#include <iostream>' or use 'std::cout' before each call to 'cout'

Example markupstd::cout &lt;&lt; &quot;Hello World!&#92;n&quot;;

Im not sure if that will solve the problem…I code in C mostly. I did code in C++ for a while a few years back but I wanted to learn more about the more complex elements such as pointers, dynamic memory allocation, etc so I went and started to learn C.

EDIT: Tested the OPs code as is and using '#include <iostream>' instead of '#include <iostream.h>' will remove the errors shown above but will add another error

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

You would then have to add what I had stated above to remove that error. What the 'using ….' directive does is declares the classes, objects, functions in the standard library eg 'cout, cin, string, etc' so that they maybe used.

Again…Im not entirely sure on my explanation (Pieced together from various sources).

Another problem you may face is when you run the executable, command prompt will flash displaying the output for a spilt second. To solve this problem, the following url will help http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1043803465&id=1043284385

Regards CyberLemming


ghost's Avatar
0 0

The errors are pretty self-expanitory, you're trying to use a deprecated header file first of all, just replace your code with this.

#include &lt;iostream&gt;

int main(int argc, char **argv)
{
    std::cout &lt;&lt; &quot;Hello world!&quot; &lt;&lt; std::endl;
    return 0;
}

ghost's Avatar
0 0

i think i need to reinstall it but i tried urs protokol and it sed [Linker error] undefined reference to `WinMain@16' ld returned 1 exit status


ghost's Avatar
0 0

same error with urs cyberlemming


ghost's Avatar
0 0

i uninstalled it. i'll reinstall it from a diffrent site tomarrow.


ghost's Avatar
0 0

Ughh.. that's because you've defined your project to be a Win32 application which searches for the entry point at WinMain() not main(), you can change recreate the project as a Console application or just change the compiler settings.


bl4ckc4t's Avatar
Banned
0 0

Simple Fix.

You forgot

using namespace std;

**using namespace** std;
int main()
{
**cout** &lt;&lt; &quot;Hello, World!&#92;n&quot;;
system(&quot;pause&quot;);
**return** 0;
}```


[edit] removed smilies[/edit]

ghost's Avatar
0 0

I use codewarrior and I've never used "using namespace std;" in it, but I'm also fairly new to it, so it might just be more advanced than I am.


ghost's Avatar
0 0

bl4ckc4t: No.. iostream.h is a deprecated header that as far as I remember, actually makes it so you don't need to include the std namespace. It is also deprecated as I've already stated as well and should be replaced with the standard iostream header file. Also, using namespace std; is not good coding practice. If the author of the thread reads my previous comment he'll realize the program is looking for the wrong entry point in the program.


ghost's Avatar
0 0

when using dev++ youll need a system("pause"); or a cin statement to keep the programm from running and closing really fast