Sign in to follow this  
Chris528

Strange issue with std::vector

Recommended Posts

I'm getting a really strange error.
I defined std::vector<std::string> m_gamedata; in a class as a member variable.
I created an instance of the class in a function of another class and when i went to use "push_back" i got the following error.
Error 19 error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::push_back' : cannot convert parameter 1 from 'std::string' to 'char' f:\testapps\common\config_handler.h 279

Share this post


Link to post
Share on other sites

Providing code helps others help you.
 
You're calling std::string::push_back. Without the code, I cannot tell you why.

std::string pkey1val = pKey1->m_pValue;
current_config->m_gamedata[i].push_back(pkey1val); Edited by Chris528

Share this post


Link to post
Share on other sites

It sounds like you're accidentally accessing the element in the vector, and then calling push_back().
 
std::string also has a push_back() function for pushing back chars onto the string.
 
Maybe you're accidentally doing:

m_gamedata[0].push_back(str); //Incorrect. Calling std::string::push_back()
[background=#fafbfc]Instead of:[/size][/background]

m_gamedata.push_back(str); //Correct. Calling std::vector::push_back().
Thank you very much, that was it. I'm embarrassed that I missed that, lol.

Share this post


Link to post
Share on other sites

std::string pkey1val = pKey1->m_pValue;
current_config->m_gamedata[i].push_back(pkey1val);

Yeah, that's saying:

m_gamedata[i]     //Access the string held at position 'i' inside the vector called m_gamedata.
   .push_back(pkey1val); //Call the 'push_back()' function on the string we just accessed.

[b][Edit:][/b] Whoops, I keep posting two seconds after you. laugh.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this