Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 1st, 2006, 9:40 PM   #1
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
Operator Error Causing Vector BS

I still do understand why I can never get basic crap to work! So annoying...

	for ( unsigned int i = 0; i <= o_game->m_msgList.size( ); i++)
	{
		TextOut(hdc, 10, 400, o_game->m_msgList[i], sizeof ( o_game->m_msgList[i] ) );
	}


Error
------ Build started: Project: Delectria, Configuration: Debug Win32 ------
Compiling...
game.cpp
c:\documents and settings\k\my documents\visual studio 2005\projects\delectria\delectria\game.h(18) : error C3203: 'basic_string' : unspecialized class template can't be used as a template argument for template parameter '_Ty', expected a real type
c:\documents and settings\k\my documents\visual studio 2005\projects\delectria\delectria\game.cpp(15) : error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'std::string' to 'const int &'
        with
        [
            _Ty=int
        ]
        Reason: cannot convert from 'std::string' to 'const int'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Build log was saved at "file://c:\Documents and Settings\K\My Documents\Visual Studio 2005\Projects\Delectria\Delectria\Debug\BuildLog.htm"
Delectria - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

this is dumb!

EDIT:
Yes i understand the msg's that will be outputing will paint over each other i haven't done the math yet
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old Jul 1st, 2006, 10:02 PM   #2
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 259
Rep Power: 3 Cache is on a distinguished road
Main changes in bold:
for (size_t i = 0; i < o_game->m_msgList.size(); ++i)
{
	::TextOut(hdc, 10, 400, o_game->m_msgList[i].c_str(), 
		o_game->m_msgList[i].size() );
}
Cache is offline   Reply With Quote
Old Jul 1st, 2006, 10:06 PM   #3
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5 grumpy is on a distinguished road
You haven't given enough information. I'm guessing m_msgList is an array (or maybe a container, such as a std::vector) of std::strings.

A few hints that might help (with this error, and other issues)

1) TextOut() in the win32 API expects to receive a C-style string (an array of char delimited by a zero byte) as it's fourth argument, not a std::string. If o_game->m_msgList[i] is a std::string, it needs to be converted to a C-style string. For example; o_game->m_msgList[i].c_str().

2) The 5th argument passed to TextOut() is the length of the string. The sizeof operator does not produce the length of a string (except in some special cases, but yours isn't one of them). If we assume (again) that o_game->m_msgList[i] is a std::string, one way of computing the length of the string is o_game->m_msgList[i].length().

3) If your loop is intended to work on all elements of the array, it will work from zero to o_game->m_msgListsize()-1. Your termination clause i <= o_game->m_msgList.size() does not achieve that; it needs to be changed to i < o_game->m_msgList.size()

You will usually find things easier if you put some effort into understanding what is going on before you write your code, rather than just throwing poorly thought-out code at the compiler and wondering why it complains.
grumpy is offline   Reply With Quote
Old Jul 2nd, 2006, 1:52 PM   #4
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
thanks a ton for your help! (both of u)
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:20 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC