Very Basic C++ Problems, Installation and Hello World

Hello,
I am trying to learn some basic C++ over the summer for school next semester. However, I am running into a lot of very basic problems just getting started. I am trying to run the Eclipse IDE, so I installed the IDE with C/C++ support, as well with a Java IDK (Which Eclipse was telling me it needed). I got eclipse up and running, but whenever I attempt to write a basic hello world program, I get errors.

#include <iostream>

int main()
{
std::cout<<"Hello, World!";
}

I get red underlines under the #include <iostream> and cout parts of the code. under #include <iostream> it says "unresolved inclusion: <iostream>", and under cout it says "symbol 'cout' could not be resolved". If I try to run the program, it tells me "Launch Failed. Binary Not Found." I have had similarly frustrating problems with other IDE's, such as Netbeans. I have tried using the return command at the end, but that does not fix anything. I suspect that I am doing something small wrong, or maybe have not installed all the neccesary components or something, but I can not figure out what. Any insight or advice would be much appreciated.
Make sure you compile the program as C++, not C.
Last edited on
closed account (iG3b7k9E)
You need to space them out like this:
1
2
3
4
5
6
#include  <iostream>

int main()
{
std::cout << "Hello, World!";
}

and not like this: (what you have.)
1
2
3
4
5
6
#include <iostream>

int main()
{
std::cout<<"Hello, World!";
}


And if you want to make a longer program and you don't want to type std::cout
every time you could put using namespace std after #include <iostream>
Last edited on
It should work with and without extra spaces. The only difference is that the code becomes easier to read in my opinion.
Last edited on
closed account (zb0S216C)
RandomStuff wrote:
"And if you want to make a longer program and you don't want to type std::cout
every time you could put using namespace std after #include <iostream> "

That's a personal preference. Besides, using namespace std has devastating consequences when use incorrectly; don't get too comfortable.

Also, has your source file got a .C extension? That's usually a small mistake that has unexpected results.

Wazzak
Last edited on
closed account (iG3b7k9E)
Ok I got it, you have to put
1
2
3
4
5
#include<iostream>
using namespace std;
int main(){
cout<<"Hello, World!";
getchar();}

If you notice I made it very compressed but what I changed was I added getchar(); at the end. That was your problem and I know it is because I tested it several different ways and this for some reason was the only one that worked.

I hope this helps.
@RandomStuff
I don't believe that is the issue. They're having issues compiling, and none of the things you pointed out actually help compile the program.

I do believe that the issue is the Eclipse IDE. I tried using it before I returned to Code::Blocks and it refused to compile. I was under the impression that the compiler that it came with was also a C++ compiler, but I believe it only can compile JAVA, which makes it a bad IDE imho. There is a bunch of things that you'll never need in it, and doesn't even have a built in compiler for what you want. Unless, I, like the OP, did something wrong, which is completely possible, I have steered away from Eclipse. It also seems very bloated due to the environment targeting JAVA development and not C++.

I would prefer using the Code::Blocks IDE with the MingW compiler. Just google Code::Blocks and when you get to the download page, I believe there is an option to include the MingW compiler. Choose that one and install. The IDE is a bare minimum, but has everything I've needed so far from an IDE.
closed account (iG3b7k9E)
Doing what i did worked fine.
Also, besides that you should try visual c++ express if you don't like any of those. And the
using namespace std;
I have read that it could cause problems in future when using multiple classes and different namespaces so it is often better to call the namespace when you are writing the code
std::cout << "You'r mom is a pineapple" << std::endl;
@RandomStuff
I didn't say that your program didn't work, I'm saying that I don't believe that the OP was having issues with the IDE they were using. I am not a fan of the Eclipse IDE since I don't believe it comes with a compiler and since it's targetted more towards JAVA development.

@curscascis
You're correct, the using namespace std; call isn't suggested as when you use another namespace, you could end up with conflicting names.
Topic archived. No new replies allowed.