LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-14-2005, 09:35 AM   #1
BACTRATE
Member
 
Registered: Jan 2004
Location: NORTH WEST UK
Posts: 180

Rep: Reputation: 30
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
 
Old 03-14-2005, 09:46 AM   #2
benjithegreat98
Senior Member
 
Registered: Dec 2003
Location: Shelbyville, TN, USA
Distribution: Fedora Core, CentOS
Posts: 1,019

Rep: Reputation: 45
#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;
}

Last edited by benjithegreat98; 03-14-2005 at 09:47 AM.
 
Old 03-14-2005, 09:47 AM   #3
supersucker
Member
 
Registered: Jul 2004
Location: Berlin
Distribution: fedora 3
Posts: 79

Rep: Reputation: 15
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
 
Old 03-14-2005, 10:05 AM   #4
BACTRATE
Member
 
Registered: Jan 2004
Location: NORTH WEST UK
Posts: 180

Original Poster
Rep: Reputation: 30
Thanks

Sorry but using namespace std throws up even more errors.But thanks for thr help.

Dave
 
Old 03-14-2005, 10:17 AM   #5
benjithegreat98
Senior Member
 
Registered: Dec 2003
Location: Shelbyville, TN, USA
Distribution: Fedora Core, CentOS
Posts: 1,019

Rep: Reputation: 45
What's the error message? Did you use the semicolon?
 
Old 03-14-2005, 11:28 AM   #6
BACTRATE
Member
 
Registered: Jan 2004
Location: NORTH WEST UK
Posts: 180

Original Poster
Rep: Reputation: 30
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> >:perator[](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> >:perator[](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> >:perator[](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:perator<< <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
 
Old 03-14-2005, 11:43 AM   #7
__J
Senior Member
 
Registered: Dec 2004
Distribution: Slackware, ROCK
Posts: 1,973

Rep: Reputation: 46
distro?
do you have libstdc++?
 
Old 03-14-2005, 11:51 AM   #8
benjithegreat98
Senior Member
 
Registered: Dec 2003
Location: Shelbyville, TN, USA
Distribution: Fedora Core, CentOS
Posts: 1,019

Rep: Reputation: 45
use the command g++ instead of gcc
g++ hello.cpp -o hello
then you can ./hello
 
Old 03-15-2005, 06:05 AM   #9
BACTRATE
Member
 
Registered: Jan 2004
Location: NORTH WEST UK
Posts: 180

Original Poster
Rep: Reputation: 30
g++ still yhe same but cout error

g++ still the same but cout error only .Still looking for libstdc++.

Thanks
Dave
 
Old 03-15-2005, 10:25 AM   #10
leadazide
Member
 
Registered: Apr 2004
Location: Germany
Distribution: SuSE 11.0, Ubuntu 7.10
Posts: 390

Rep: Reputation: 30
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
 
Old 03-15-2005, 10:53 AM   #11
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
The code should be as follows,

Code:
#include <iostream>
using namespace std;
int main (void)
{
     cout << "Hello, World!\n";
   
     return 0;
}
to compile it you would do something like

Code:
g++ -o hello hello.cpp
 
Old 03-15-2005, 11:43 AM   #12
BACTRATE
Member
 
Registered: Jan 2004
Location: NORTH WEST UK
Posts: 180

Original Poster
Rep: Reputation: 30
Thanks

Thanks to all I will try latest suggestions and report.

Cheers

Dave
 
Old 03-16-2005, 06:15 AM   #13
BACTRATE
Member
 
Registered: Jan 2004
Location: NORTH WEST UK
Posts: 180

Original Poster
Rep: Reputation: 30
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
 
Old 07-24-2008, 07:39 AM   #14
Micky_123
LQ Newbie
 
Registered: Dec 2007
Posts: 17

Rep: Reputation: 0
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
 
Old 07-24-2008, 12:57 PM   #15
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Why did you reply to a thread that's 3 years old and no longer requires a solution?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MythTV wont compile murffatksig Linux - Software 1 09-05-2004 05:08 AM
Pureftp wont compile chongo2002 Linux - Software 0 01-28-2004 06:53 AM
why wont it compile? saturn_vk Linux - Software 11 03-30-2003 07:11 AM
Why doesn't this simple program compile? SparceMatrix Programming 4 08-27-2002 03:37 AM
QT, urm. It wont compile anything. f0d Programming 1 04-24-2002 04:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration