![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
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 |
|
|
|
|
|
#2 |
|
Hobbyist
Join Date: Sep 2005
Posts: 259
Rep Power: 3
![]() |
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() );
} |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#4 |
|
Expert Programmer
|
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|