LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-26-2007, 02:22 PM   #1
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Rep: Reputation: 30
C++ simple problem, doesn't recognize some std::cout


I don't know what's goin' on, it happens to me in every project but I don't know what I'm doing wrong! looked for solution in the code for over a hour.


here's some code :
Code:
<b>main.cpp</b>

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream>
#include <cstdlib>

// int main(int argc, char *argv[])
int main()
{
	
	std::cout << "Hello, world!" << std::endl;
	int nCounter=5;
	CImage myClass(nCounter)
	return 0;
// 	return EXIT_SUCCESS;
}


<b> cimage.cpp</b>

#include "cimage.h"


CImage::CImage(int nCount)
{
	int m_nCount=nCount;
	<b>cout << m_nCount << endl;</b>
}


CImage::~CImage()
{
}



<b> cimage.h</b>
#ifndef CIMAGE_H
using namespace std;
#define CIMAGE_H



class CImage{
public:
    CImage(int nCount);

    ~CImage();
	static const int m_nCount=0;

};

The problem is that it says that the cout and endl in that bold line are not in std
even if I do instead std::cout and std::endl
Thanks for your help!
 
Old 06-26-2007, 02:27 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Because you still need to
Code:
#include <iostream>
in any source files that use cout, cerr, endl, etc.
 
Old 06-28-2007, 02:07 PM   #3
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Dark_Helmet
Because you still need to
Code:
#include <iostream>
in any source files that use cout, cerr, endl, etc.
Is there more error?
it says now that there are multiple definitions for the constructor...

weird//

Quote:
cd '/home/zuki/Scripts/stigno2/debug' && WANT_AUTOCONF_2_5="1" WANT_AUTOMAKE_1_6="1" gmake -k
gmake all-recursive
Making all in src
/bin/sh ../libtool --tag=CXX --mode=link g++ -O0 -g3 -o stigno2 stigno2.o cimage.o
g++ -O0 -g3 -o stigno2 stigno2.o cimage.o
cimage.o(.text+0x104): In function `CImage::CImage(int)':
/home/zuki/Scripts/stigno2/src/cimage.cpp:26: multiple definition of `CImage::CImage(int)'
stigno2.o(.text+0x104):/home/zuki/Scripts/stigno2/src/cimage.cpp:26: first defined here
cimage.o(.text+0x112): In function `CImage::CImage(int)':
/home/zuki/Scripts/stigno2/src/cimage.cpp:26: multiple definition of `CImage::CImage(int)'
stigno2.o(.text+0x112):/home/zuki/Scripts/stigno2/src/cimage.cpp:26: first defined here
cimage.o(.text+0x120): In function `CImage::~CImage()':
/home/zuki/Scripts/stigno2/src/cimage.cpp:33: multiple definition of `CImage::~CImage()'
stigno2.o(.text+0x120):/home/zuki/Scripts/stigno2/src/cimage.cpp:33: first defined here
cimage.o(.text+0x126): In function `CImage::~CImage()':
/home/zuki/Scripts/stigno2/src/cimage.cpp:33: multiple definition of `CImage::~CImage()'
stigno2.o(.text+0x126):/home/zuki/Scripts/stigno2/src/cimage.cpp:33: first defined here
collect2: ld returned 1 exit status
gmake[2]: *** [stigno2] Error 1
gmake[2]: Target `all' not remade because of errors.
gmake[2]: Nothing to be done for `all-am'.
gmake[1]: *** [all-recursive] Error 1
gmake: *** [all] Error 2
*** Exited with status: 2 ***

Last edited by itz2000; 06-28-2007 at 02:09 PM.
 
Old 06-28-2007, 08:18 PM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
You need to #endif at the end of cimage.h
Do you by any chance #include cimage.cpp in any other files?, the #include should be cimage.h, the header file not the source code.
 
  


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
VectorLinux 5.1 STD installation problem davidkline Linux - Kernel 1 04-25-2007 10:33 AM
pblm with std::cout while compiling adilturbo Programming 7 06-12-2006 07:56 AM
`cout' undeclared in namespace `std' aw_wolfe Programming 1 04-30-2005 09:25 PM
c++ cout not working :( Longinus Programming 10 08-01-2004 07:32 PM
KNOPPIX-STD Internet Problem - PLEASE HELP rotton Linux - Newbie 1 06-09-2004 11:41 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:50 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