CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Deploying Windows Server 2008 with System Center
  • Remote Desktop Protocol Performance Improvements in Windows Server 2008 R2 and Windows 7
  • The Microsoft Dynamics CRM Security Model
  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 5th, 2009, 10:38 PM
    WillJacobs WillJacobs is offline
    Junior Member
     
    Join Date: Oct 2009
    Posts: 2
    WillJacobs is an unknown quantity at this point (<10)
    Errors I can't figure out.

    The entirety of my error:
    Code:
    scrab101.cpp: In function ‘void drawreplace(char&, char&, char&, char&, char&, std::ifstream&)’:
    scrab101.cpp:1159: error: no match for ‘operator<<’ in ‘scrab101 << "replace "’
    scrab101.cpp:1160: error: no matching function for call to ‘std::vector<char, std::allocator<char> >::erase(int)’
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:110: note: candidates are: typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = char, _Alloc = std::allocator<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:122: note:                 typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, __gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = char, _Alloc = std::allocator<char>]
    scrab101.cpp:1164: error: no match for ‘operator<<’ in ‘scrab101 << "replace "’
    scrab101.cpp:1165: error: no matching function for call to ‘std::vector<char, std::allocator<char> >::erase(int)’
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:110: note: candidates are: typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = char, _Alloc = std::allocator<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:122: note:                 typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, __gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = char, _Alloc = std::allocator<char>]
    scrab101.cpp:1169: error: no match for ‘operator<<’ in ‘scrab101 << "replace "’
    scrab101.cpp:1170: error: no matching function for call to ‘std::vector<char, std::allocator<char> >::erase(int)’
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:110: note: candidates are: typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = char, _Alloc = std::allocator<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:122: note:                 typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, __gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = char, _Alloc = std::allocator<char>]
    scrab101.cpp:1174: error: no match for ‘operator<<’ in ‘scrab101 << "replace "’
    scrab101.cpp:1175: error: no matching function for call to ‘std::vector<char, std::allocator<char> >::erase(int)’
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:110: note: candidates are: typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = char, _Alloc = std::allocator<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:122: note:                 typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, __gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = char, _Alloc = std::allocator<char>]
    scrab101.cpp:1179: error: no match for ‘operator<<’ in ‘scrab101 << "replace "’
    scrab101.cpp:1180: error: ‘bcpm’ was not declared in this scope
    scrab101.cpp:1184: error: no match for ‘operator<<’ in ‘scrab101 << "replace "’
    scrab101.cpp:1185: error: no matching function for call to ‘std::vector<char, std::allocator<char> >::erase(int)’
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:110: note: candidates are: typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = char, _Alloc = std::allocator<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:122: note:                 typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, __gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = char, _Alloc = std::allocator<char>]
    scrab101.cpp:1189: error: no match for ‘operator<<’ in ‘scrab101 << "replace "’
    scrab101.cpp:1190: error: no matching function for call to ‘std::vector<char, std::allocator<char> >::erase(int)’
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:110: note: candidates are: typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = char, _Alloc = std::allocator<char>]
    /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:122: note:                 typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >, __gnu_cxx::__normal_iterator<typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer, std::vector<_Tp, _Alloc> >) [with _Tp = char, _Alloc = std::allocator<char>]
    scrab101.cpp:1249: error: no match for ‘operator<<’ in ‘scrab101 << "draw "’
    scrab101.cpp:1253: error: expected primary-expression before ‘char’
    scrab101.cpp:1253: error: expected primary-expression before ‘char’
    scrab101.cpp:1253: error: expected primary-expression before ‘char’
    scrab101.cpp:1253: error: expected primary-expression before ‘char’
    scrab101.cpp:1253: error: expected primary-expression before ‘char’
    scrab101.cpp: In function ‘int main()’:
    scrab101.cpp:2047: error: invalid initialization of reference of type ‘std::ifstream&’ from expression of type ‘std::ofstream’
    scrab101.cpp:924: error: in passing argument 6 of ‘void drawreplace(char&, char&, char&, char&, char&, std::ifstream&)’
    caen-vnc02%
    My whole code is far too long to post, so I will just describe the parts around where it doesn't seem to be working... I am declaring and opening an ifstream in int main, and then I am calling a procedure which uses that ifstream. The ifstream is not declared, opened or closed in the procedure. I am calling 5 chars and the ifstream all by reference in the procedure. I am cannot figure out what is wrong. The "no match for opporator <<" is absolutely baffeling to me.

    This is my procedure...

    Code:
    void drawreplace(char & ch1, char & ch2, char & ch3, char & ch4, char & ch5, ifstream & scrab101) // draw and replace
    { 
    	vector <char> current(5);
    	current[0] = ch1;
    	current[1] = ch2;
    	current[2] = ch3;
    	current[3] = ch4;
    	current[4] = ch5;
    	vector <char> qz(5);
    	vector <char> jx(5);
    	vector <char> k(5);
    	vector <char> fhvwy(5);
    	vector <char> bcmp(5);
    	vector <char> dg(5);
    	vector <char> aeilnorstu(5);
    	switch(current[0]){
    		case 'q':
    		case 'z':
    		qz.push_back(ch1);
    		break;
    		case 'j':
    		case 'x':
    		jx.push_back(ch1);
    		break;
    		case 'k':
    		k.push_back(ch1);
    		break;
    		case 'f':
    		case 'h':
    		case 'v':
    		case 'w':
    		case 'y':
    		fhvwy.push_back(ch1);
    		break;
    		case 'b':
    		case 'c':
    		case 'm':
    		case 'p':
    		bcmp.push_back(ch1);
    		break;
    		case 'd':
    		case 'g':
    		dg.push_back(ch1);
    		break;
    		case 'a':
    		case 'e':
    		case 'i':
    		case 'l':
    		case 'n':
    		case 'o':
    		case 'r':
    		case 's':
    		case 't':
    		case 'u':
    		aeilnorstu.push_back(ch1);
    		break;
    	}
    	switch(current[1]){
    		case 'q':
    		case 'z':
    		qz.push_back(ch2);
    		break;
    		case 'j':
    		case 'x':
    		jx.push_back(ch2);
    		break;
    		case 'k':
    		k.push_back(ch2);
    		break;
    		case 'f':
    		case 'h':
    		case 'v':
    		case 'w':
    		case 'y':
    		fhvwy.push_back(ch2);
    		break;
    		case 'b':
    		case 'c':
    		case 'm':
    		case 'p':
    		bcmp.push_back(ch2);
    		break;
    		case 'd':
    		case 'g':
    		dg.push_back(ch2);
    		break;
    		case 'a':
    		case 'e':
    		case 'i':
    		case 'l':
    		case 'n':
    		case 'o':
    		case 'r':
    		case 's':
    		case 't':
    		case 'u':
    		aeilnorstu.push_back(ch2);
    		break;
    	}
    	switch(current[2]){
    		case 'q':
    		case 'z':
    		qz.push_back(ch3);
    		break;
    		case 'j':
    		case 'x':
    		jx.push_back(ch3);
    		break;
    		case 'k':
    		k.push_back(ch3);
    		break;
    		case 'f':
    		case 'h':
    		case 'v':
    		case 'w':
    		case 'y':
    		fhvwy.push_back(ch3);
    		break;
    		case 'b':
    		case 'c':
    		case 'm':
    		case 'p':
    		bcmp.push_back(ch3);
    		break;
    		case 'd':
    		case 'g':
    		dg.push_back(ch3);
    		break;
    		case 'a':
    		case 'e':
    		case 'i':
    		case 'l':
    		case 'n':
    		case 'o':
    		case 'r':
    		case 's':
    		case 't':
    		case 'u':
    		aeilnorstu.push_back(ch3);
    		break;
    	}
    	switch(current[3]){
    		case 'q':
    		case 'z':
    		qz.push_back(ch4);
    		break;
    		case 'j':
    		case 'x':
    		jx.push_back(ch4);
    		break;
    		case 'k':
    		k.push_back(ch4);
    		break;
    		case 'f':
    		case 'h':
    		case 'v':
    		case 'w':
    		case 'y':
    		fhvwy.push_back(ch4);
    		break;
    		case 'b':
    		case 'c':
    		case 'm':
    		case 'p':
    		bcmp.push_back(ch4);
    		break;
    		case 'd':
    		case 'g':
    		dg.push_back(ch4);
    		break;
    		case 'a':
    		case 'e':
    		case 'i':
    		case 'l':
    		case 'n':
    		case 'o':
    		case 'r':
    		case 's':
    		case 't':
    		case 'u':
    		aeilnorstu.push_back(ch4);
    		break;
    	}
    	switch(current[4]){
    		case 'q':
    		case 'z':
    		qz.push_back(ch5);
    		break;
    		case 'j':
    		case 'x':
    		jx.push_back(ch5);
    		break;
    		case 'k':
    		k.push_back(ch5);
    		break;
    		case 'f':
    		case 'h':
    		case 'v':
    		case 'w':
    		case 'y':
    		fhvwy.push_back(ch5);
    		break;
    		case 'b':
    		case 'c':
    		case 'm':
    		case 'p':
    		bcmp.push_back(ch5);
    		break;
    		case 'd':
    		case 'g':
    		dg.push_back(ch5);
    		break;
    		case 'a':
    		case 'e':
    		case 'i':
    		case 'l':
    		case 'n':
    		case 'o':
    		case 'r':
    		case 's':
    		case 't':
    		case 'u':
    		aeilnorstu.push_back(ch5);
    		break;
    	}
    	int qzsize, jxsize, ksize, fhvwysize, bcmpsize, dgsize, aeilnorstusize;
    	qzsize = qz.size();
    	jxsize = jx.size();
    	ksize = k.size();
    	fhvwysize = fhvwy.size();
    	bcmpsize = bcmp.size();
    	dgsize = dg.size();
    	aeilnorstusize = aeilnorstu.size();
    	if(qzsize != 0)
    	{
    		scrab101 << "replace " << qz[0] << endl;
    		qz.erase(0);
    	}
    	else if(jxsize != 0)
    	{
    		scrab101 << "replace " << jx[0] << endl;
    		jx.erase(0);
    	}
    	else if(ksize != 0)
    	{
    		scrab101 << "replace " << k[0] << endl;
    		k.erase(0);
    	}
    	else if(fhvwysize != 0)
    	{
    		scrab101 << "replace " << fhvwy[0] << endl;
    		fhvwy.erase(0);
    	}
    	else if(bcmpsize != 0)
    	{
    		scrab101 << "replace " << bcmp[0] << endl;
    		bcpm.erase(0);
    	}
    	else if(dgsize != 0)
    	{
    		scrab101 << "replace " << dg[0] << endl;
    		dg.erase(0);
    	}
    	else if(aeilnorstusize != 0)
    	{
    		scrab101 << "replace " << aeilnorstu[0] << endl;
    		aeilnorstu.erase(0);
    	}
    	qzsize = qz.size();
    	jxsize = jx.size();
    	ksize = k.size();
    	fhvwysize = fhvwy.size();
    	bcmpsize = bcmp.size();
    	dgsize = dg.size();
    	aeilnorstusize = aeilnorstu.size();
    	vector <char> newstring(5);
    	int n = 0;
    	int m;
    	m = qzsize;
    	for(m; m > 0; m--)
    	{
    		newstring[n] = qz[m-1];
    		n++;
    	}
    	m = jxsize;
    	for(m; m > 0; m--)
    	{
    		newstring[n] = qz[m-1];
    		n++;
    	}
    	m = ksize;
    	for(m; m > 0; m--)
    	{
    		newstring[n] = qz[m-1];
    		n++;
    	}
    	m = fhvwysize;
    	for(m; m > 0; m--)
    	{
    		newstring[n] = qz[m-1];
    		n++;
    	}
    	m = bcmpsize;
    	for(m; m > 0; m--)
    	{
    		newstring[n] = qz[m-1];
    		n++;
    	}
    	m = dgsize;
    	for(m; m > 0; m--)
    	{
    		newstring[n] = qz[m-1];
    		n++;
    	}
    	m = aeilnorstusize;
    	for(m; m > 0; m--)
    	{
    		newstring[n] = qz[m-1];
    		n++;
    	}
    	ch1 = newstring[0];
    	ch2 = newstring[1];
    	ch3 = newstring[2];
    	ch4 = newstring[3];
    	ch5 = singlerand(ch1);
    	scrab101 << "draw " << ch5 << endl;
    	bool q = anyword(ch1);
    	if(!q)
    	{
    		drawreplace(char & ch1, char & ch2, char & ch3, char & ch4, char & ch5);
    	}
    	else
    	{
    		return;
    	}
    }
    I appreciate any help I can get thank you.
    Reply With Quote
      #2    
    Old November 6th, 2009, 11:40 AM
    MrViggy's Avatar
    MrViggy MrViggy is offline
    Elite Member
     
    Join Date: Feb 2002
    Posts: 3,833
    MrViggy has much to be proud of (1500+) MrViggy has much to be proud of (1500+) MrViggy has much to be proud of (1500+) MrViggy has much to be proud of (1500+) MrViggy has much to be proud of (1500+) MrViggy has much to be proud of (1500+) MrViggy has much to be proud of (1500+) MrViggy has much to be proud of (1500+) MrViggy has much to be proud of (1500+) MrViggy has much to be proud of (1500+) MrViggy has much to be proud of (1500+)
    Re: Errors I can't figure out.

    Did you include <fstream>?

    Viggy
    Reply With Quote
      #3    
    Old November 6th, 2009, 12:07 PM
    Paul McKenzie Paul McKenzie is offline
    Elite Member
    Power Poster
     
    Join Date: Apr 1999
    Posts: 20,959
    Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+) Paul McKenzie has a reputation beyond repute (3000+)
    Re: Errors I can't figure out.

    Quote:
    Originally Posted by WillJacobs View Post
    The entirety of my error:
    Look at the last line. You could have easily came up with something much simpler:
    Code:
    #include <fstream>
    
    void drawreplace(char&, char&, char&, char&, char&, std::ifstream&);
    
    int main()
    {
       char c;
       std::ifstream dummy;
       drawreplace(c, c, c, c, c, dummy);
    }
    This compiles fine.

    Now given the above, get it to give the same error as you're seeing now. If you can't, then examine the code above to see what it does that is different than what yours does.

    Every C++ compiler error can be reproduced with a simple example, there are no exceptions to that rule.

    Regards,

    Paul McKenzie
    Reply With Quote
      #4    
    Old November 6th, 2009, 12:07 PM
    D_Drmmr's Avatar
    D_Drmmr D_Drmmr is offline
    Member
     
    Join Date: Jul 2005
    Location: Netherlands
    Posts: 442
    D_Drmmr is a jewel in the rough (200+) D_Drmmr is a jewel in the rough (200+) D_Drmmr is a jewel in the rough (200+)
    Re: Errors I can't figure out.

    nvm
    __________________
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > C++ (Non Visual C++ Issues)


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    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 On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 01:04 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.