Conversion of std::basic_string to std::string?

Started by
21 comments, last by Zahlman 18 years, 5 months ago
Quote:Original post by TDragon
I answered your questions in an edit to my previous post just now. Sorry for any confusion/trouble. What I meant about passing by value was something along the lines of:
std::string str = _strStringName;parser.GetIntValuestr(str, "frame", iStopY);


Oh, I see what you mean. Yeah, that makes more sense, but my problem remains.
Advertisement
Which problem? Surely you're not still getting the original error message about being unable to convert from 'std::allocator<_Ty>::value_type' to 'std::string'?
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
Quote:
bool CMyFont::Initialize(const Int8* _pcIniFileName, std::string _strStringName,
Float32 _fXPosition, Float32 _fYPosition)
{
CINIParser parser(_pcIniFileName);
Int32 iStringLength = static_cast<Int32>(_strStringName.length());

for(int i = 0; i < iStringLength; i++)
{
//std::string strCurrentLetter = _strStringName;
//std::basic_string <char>::reference strCurrentLetter = _strStringName;
Int32 iStartX;
Int32 iStopX;
Int32 iStartY;
Int32 iStopY;
parser.GetIntValue(_strStringName, "frame", iStartX);
parser.GetIntValue(_strStringName, "frame", iStopX);
parser.GetIntValue(_strStringName, "frame", iStartY);
parser.GetIntValue(_strStringName, "frame", iStopY);
}

return true;
}


Yes, unfortunately. The errors are slightly different, but I think the problem is the same. Here are the errors:

Quote:
e:\Documents and Settings\David & Angela\Desktop\Rugby League Manager\Font.cpp(73): error C2664: 'CINIParser::GetIntValue' : cannot convert parameter 1 from 'std::allocator<_Ty>::value_type' to 'std::string'
with
[
_Ty=char
]
e:\Documents and Settings\David & Angela\Desktop\Rugby League Manager\Font.cpp(74): error C2664: 'CINIParser::GetIntValue' : cannot convert parameter 1 from 'std::allocator<_Ty>::value_type' to 'std::string'
with
[
_Ty=char
]
No constructor could take the source type, or constructor overload resolution was ambiguous
e:\Documents and Settings\David & Angela\Desktop\Rugby League Manager\Font.cpp(75): error C2664: 'CINIParser::GetIntValue' : cannot convert parameter 1 from 'std::allocator<_Ty>::value_type' to 'std::string'
with
[
_Ty=char
]
No constructor could take the source type, or constructor overload resolution was ambiguous
e:\Documents and Settings\David & Angela\Desktop\Rugby League Manager\Font.cpp(76): error C2664: 'CINIParser::GetIntValue' : cannot convert parameter 1 from 'std::allocator<_Ty>::value_type' to 'std::string'
with
[
_Ty=char
]
No constructor could take the source type, or constructor overload resolution was ambiguous
Quote:Original post by TDragon
I answered your questions in an edit to my previous post just now. Sorry for any confusion/trouble. What I meant about passing by value was something along the lines of:
std::string str = _strStringName;parser.GetIntValuestr(str, "frame", iStopY);


Read my lips...[smile]
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
Ah. My bad. :P

I've done that, but now my error rest with this line of code:

Quote:
std::string strCurrentLetter = _strStringName;


And the error is this:

Quote:
e:\Documents and Settings\David & Angela\Desktop\Rugby League Manager\Font.cpp(67): error C2440: 'initializing' : cannot convert from 'std::allocator<_Ty>::value_type' to 'std::basic_string<_Elem,_Traits,_Ax>'
with
[
_Ty=char
]
and
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]


Is there perhaps an include file that I should be using in order for this to work properly?
All you should need to include is <string>; I wish I had a compiler with me to test it. You could try casting it to a char: std::string strCurrentLetter = static_cast< char >(_strStringName);
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
Yeah, I've already included <string>.

static_casting it to a char results in this:

Quote:
e:\Documents and Settings\David & Angela\Desktop\Rugby League Manager\Font.cpp(67): error C2440: 'initializing' : cannot convert from 'char' to 'std::basic_string<_Elem,_Traits,_Ax>'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]


Ah well. I'm not sure where to go from here. Thanks for your help, though, TDragon. :)
Hmph. The only reason I can think that the code doesn't work is that your compiler is borked or your STL is borked.
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
The operator= not working is just bizarre.

Try this instead:

strCurrentLetter.assign(1, _strStringName);

- Phil
Or, std::string strCurrentLetter(1, _strStringName);
You never know...
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++

This topic is closed to new replies.

Advertisement