1829103 Members
2174 Online
109986 Solutions
New Discussion

gcc: cout problem!

 
SOLVED
Go to solution
Fragon
Trusted Contributor

gcc: cout problem!

After having my gcc3.2 installed , I did these:
#cd /tmp
#vi hello.C
=====This is source file=====
#include
using namespace std;
main()
{
cout >> "This is a test.";
}
=====end=====================
#/usr/local/bin/gcc ./hello.C

Now I get an error message:
hello.C: In function `int main()`:
hello.C: 7: no match for `std::ostream& >> std::string&` operator

Would anyone tell me why and how to correct them?
Thank in advance!
5 REPLIES 5
T G Manikandan
Honored Contributor

Re: gcc: cout problem!

Can you try this
"cout <<" and not "cout >>"
H.Merijn Brand (procura
Honored Contributor
Solution

Re: gcc: cout problem!

Shouldn't you also be using c++ or g++ instead?


l1:/tmp 107 > cat xx.C
#include
using namespace std;
main ()
{
cout >> "This is a test.";
}
l1:/tmp 108 > gcc -o xx xx.C
xx.C: In function `int main()':
xx.C:5: no match for `std::ostream& >> const char[16]' operator
Exit 1
l1:/tmp 109 > g++ -o xx xx.C
xx.C: In function `int main()':
xx.C:5: no match for `std::ostream& >> const char[16]' operator
Exit 1
l1:/tmp 110 > perl -pi -e's/>>/<l1:/tmp 111 > gcc -o xx xx.C
/usr/ccs/bin/ld: Unsatisfied symbols:
std::ios_base::Init::~Init [in-charge]()(first referenced in /tmp/ccQ5mf0t.o) (code)
std::ios_base::Init::Init[in-charge]()(first referenced in /tmp/ccQ5mf0t.o) (code)
std::basic_ostream >& std::operator<< <:char_traits> >(std::basic_ostream >&, char const*)(first referenced in /tmp/ccQ5mf0t.o) (code)
std::cout (first referenced in /tmp/ccQ5mf0t.o) (data)
collect2: ld returned 1 exit status
Exit 1
l1:/tmp 112 > g++ -o xx xx.C
l1:/tmp 113 >
Enjoy, Have FUN! H.Merijn
Fragon
Trusted Contributor

Re: gcc: cout problem!

Thank procura!
#/usr/local/bin/g++ -o hello hello.C
OK!
But when I type:
#./hello
I get some errors just like this:
================
/usr/lib/dld.sl: Unresolved symbol: pthread_once (code) from /usr/local/lib/gcc
-lib/hppa2.0n-hp-hpux11.00/3.2/../../../libgcc_s.sl
Abort(coredump)
================
Why?
H.Merijn Brand (procura
Honored Contributor

Re: gcc: cout problem!

l1:/tmp 126 > ./xx
This is a test.l1:/tmp 127 >

Hmmm, beats me.
FWIW, I never use g++

Where did you get it from?
My port is available on https://www.beepz.com/personal/merijn
If you go for that one (including binutils-2.13 and gdb-5.2.1) please *do* read the instructions
Enjoy, Have FUN! H.Merijn

Re: gcc: cout problem!

Try linking against the pthread library explicitly (should be -lpthread for the link step).

Regards, M.