Help with IDE

Jul 3, 2011 at 3:31pm
Hi guys,

I am scratching c++ and I am a little bit confused.

In Eclipse (galileo 3.5) if I do this:

##############################################
//hello.cpp
#include <iostream>

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

It complains, but If I do this:

##############################################
#include <iostream>
using namespace std;

int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
##############################################

Eclipse is happy.

I do not understand why. It is the same thing, or am I wrong?
What is the difference?

Also, all the tutorials I can find use these two interchangeably.

Should I do this -> std::cout <<"Hello, World!\n"; ???
or this -> cout << "!!!Hello World!!!" << endl;

Thank You

Danny
Jul 3, 2011 at 3:53pm
It complains

What are the exact error(s) you're receiving?
Jul 3, 2011 at 4:19pm
It is the same, the top one compiles fine for me, are you sure you copied it over exactly as you have it in your post?
Jul 3, 2011 at 4:23pm
There is a subtle difference between '\n' and std::endl, but it often will have no effect. It certainly won't cause a compiler error. See here for details:
http://www.cplusplus.com/forum/beginner/7350/
So basically, do whichever you prefer :)

And as previous members have said, each code should work if and only if the other does. What is the compiler error you are getting.
Last edited on Jul 3, 2011 at 4:24pm
Jul 3, 2011 at 4:43pm
Hi guys,

Here is the output:

####################################
**** Build of configuration Debug for project test3 ****

make all
Building file: ../test2.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"test2.d" -MT"test2.d" -o"test2.o" "../test2.cpp"
Finished building: ../test2.cpp

Building target: test3
Invoking: GCC C++ Linker
g++ -o"test3" ./test2.o
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 7 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 11 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 12 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 13 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 14 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 15 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 16 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 17 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 18 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 19 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 20 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 21 has invalid symbol index 14
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 22 has invalid symbol index 22
/usr/lib/gcc/i486-linux-gnu/4.4.5/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [test3] Error 1
############################################

Hope it helps

Thank You

Danny
Topic archived. No new replies allowed.