LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-03-2006, 12:07 AM   #1
k1ll3r_x
Member
 
Registered: Sep 2004
Location: Laredo, TX
Distribution: Debian 11
Posts: 164

Rep: Reputation: 30
c++ code compiling error


ok, well im working on little simple stuff for my class tomorrow, i have to make a program, and i did, here it is, most of you will deduct its just a counter made to accept 10 numbers and then get the largest one
Code:
#include <iostream>

using namespace std;


int main()
{
	int counter;
	int number;
	int large;

	while(counter < 10)
	{
		std::cout << "Input a number please: "; 
		std::cin << number << std::endl;
		
		while(number > large)
		{
			large = number;
		}

		counter++;
	}
	
	std::cout<< "Largest number is: "<< largest<< std::endl; 
	return 0;
}
but when i compile!!! i get this stuff:
Code:
1>------ Build started: Project: Project4_17, Configuration: Debug Win32 ------
1>Compiling...
1>4_17.cpp
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(927) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(927) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(927) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(927) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(920) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(920) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(920) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(920) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(913) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(913) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(913) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(913) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(906) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(906) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(906) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(906) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(868) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(868) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(868) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(868) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(822) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(822) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(822) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(822) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(782) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(782) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(782) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(782) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(735) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(735) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(735) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(735) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(697) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(697) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(697) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(697) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(650) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(650) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(650) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'std::istream'
1>        C:\Program Files\Microsoft Visual Studio 8\VC\include\ostream(650) : see declaration of 'std::operator <<'
1>.\4_17.cpp(15) : error C2676: binary '<<' : 'std::istream' does not define this operator or a conversion to a type acceptable to the predefined operator
1>.\4_17.cpp(25) : error C2065: 'largest' : undeclared identifier
1>Build log was saved at "file://c:\Documents and Settings\HP_Owner\My Documents\Visual Studio 2005\Projects\Project4_17\Project4_17\Debug\BuildLog.htm"
1>Project4_17 - 42 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
i got it on my previous program and it was weird, because it went away by just erasing a few spaces, if someone can tell me what im doing wrong and how to fix it, id really appreciate the helping hand.
k1ll3r_x@hotmail.com [incase you aint registered and can message me on msn ]
 
Old 10-03-2006, 12:12 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by k1ll3r_x
std::cout<< "Largest number is: "<< largest<< std:endl;
Put a space between "cout" and "<<". Also, since you have "using namespace std;" at the top, you don't need to prefix things like cout with "std::"
 
Old 10-03-2006, 12:13 AM   #3
k1ll3r_x
Member
 
Registered: Sep 2004
Location: Laredo, TX
Distribution: Debian 11
Posts: 164

Original Poster
Rep: Reputation: 30
same thing, no change
 
Old 10-03-2006, 02:35 AM   #4
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Code:
#include <iostream>

int main()
{
	//intialise variables
	int counter(0);
	int number(0);
	int large(0);

	while(counter < 10)
	{
		std::cout << "Input a number please: "; 
		//change insertion operator into extraction
		//std::cin followed by std::endl makes no sense.
		std::cin >> number;
		
		//while loop works but if is better as you only need 
		//the statement to work at most once an iteration
		if(number > large)
		{
			large = number;
		}

		counter++;
	}
	//typo "largest"
	std::cout<< "Largest number is: "<< large<< std::endl; 
	return 0;
}
Without instialising the variables what will counter < 10 evaluate to on the first run? Using the wrong stream operator is the source of many problems for beginners and sometimes even the more advanced lol.

Last edited by dmail; 10-03-2006 at 02:41 AM.
 
Old 10-03-2006, 02:41 AM   #5
pushpen
LQ Newbie
 
Registered: Aug 2004
Posts: 6

Rep: Reputation: 0
dmail's code should work with one correction
std::cout<< "Largest number is: "<< large << std::endl;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Kernel Filter Failed error while compiling packet capturing code on FC2 Prakhardeep Programming 3 08-10-2011 04:55 AM
compiling C code vose Programming 29 10-08-2004 07:28 AM
Compiling C code with libraries OldGuru Programming 4 09-18-2004 07:06 PM
error in compiling simple code Tinku Programming 6 09-17-2004 01:38 AM
compiling code ripmaster Linux - Software 2 03-06-2004 09:07 PM

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

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