Simple program wont compile
This wont compile-
#include <iostream> int main() { cout <<"Hello World\n"; return 0; } Get error " cout undeclared." Thanks for any help in advance Dave |
#include <iostream>
using namespace std; int main() { cout <<"Hello World\n"; return 0; } ------------------ or ------------------ #include <iostream> int main() { std::cout <<"Hello World\n"; return 0; } |
its a long time ago scince i have programmed something in C++,
but i think something like: using namespace::std; at the beginning of your programm should solve your problem........:-) hope this helped |
Thanks
Sorry but using namespace std throws up even more errors.But thanks for thr help.
Dave |
What's the error message? Did you use the semicolon?
|
Yes used semicolon get
dave@localhost dave]$ cd downloads [dave@localhost downloads]$ gcc hello.cpp /home/dave/tmp/cc7hxXjR.o(.text+0xd): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': : undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const' /home/dave/tmp/cc7hxXjR.o(.text+0x60): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': : undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const' /home/dave/tmp/cc7hxXjR.o(.text+0x9d): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': : undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const' /home/dave/tmp/cc7hxXjR.o(.text+0xc8): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': : undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const' /home/dave/tmp/cc7hxXjR.o(.text+0x129): In function `main': : undefined reference to `std::cout' /home/dave/tmp/cc7hxXjR.o(.text+0x12e): In function `main': : undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /home/dave/tmp/cc7hxXjR.o(.text+0x15a): In function `__static_initialization_and_destruction_0(int, int)': : undefined reference to `std::ios_base::Init::Init()' /home/dave/tmp/cc7hxXjR.o(.text+0x189): In function `__tcf_0': : undefined reference to `std::ios_base::Init::~Init()' /home/dave/tmp/cc7hxXjR.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status [dave@localhost downloads]$ Thanks Dave |
distro?
do you have libstdc++? |
use the command g++ instead of gcc
g++ hello.cpp -o hello then you can ./hello |
g++ still yhe same but cout error
g++ still the same but cout error only .Still looking for libstdc++.
Thanks Dave |
Use
using namespace std; not using namespace::std; and compile it with g++ -o hello hello.cpp or with gcc -o hello -lstdc++ hello.cpp |
The code should be as follows,
Code:
#include <iostream> Code:
g++ -o hello hello.cpp |
Thanks
Thanks to all I will try latest suggestions and report.
Cheers Dave |
Thanks -problem solved
Using
namespace std; int main (void) and compiling with g++ solved the problem. Thanks to all again much appreciated. All the best Dave |
Hi,
This code works fine on my system. #include <iostream> using namespace std; int main() { cout<<"Hello World\n"; return 0; } I compiled it using g++. You need to check the libraries if it doesn't work for u. cheers, Micky |
Why did you reply to a thread that's 3 years old and no longer requires a solution?
|
All times are GMT -5. The time now is 02:15 PM. |