• Advertisement

Archived

This topic is now archived and is closed to further replies.

What data structure to use?

This topic is 5539 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a text box that I'm creating for the UI in my game, and it can hold 10 lines of text. So I need some type of data structure to take up to ten lines, but if its totally filled and a new line is added, the last element is deleted and the the rest are bumped up by one and the new element is inserted at the beginning. I was trying to get this to work with vectors, but I can't figure out how to get my vector to take a full string. Heres the code I tried: void WriteBoxText() { std::vector::iterator iter; for(iter = stringVector.begin() ; iter != stringVector.end() ; ++iter) g_Font_small.OutputText(iter, 100, 100); } void AddLine(char* string) { static int x = 1; if(x == 10) { std::vector::iterator iter; iter = stringVector.end(); stringVector.erase(iter); x--; } stringVector.push_back(*string); x++; } //function definition for OutputText HRESULT CFont::OutputText( char* pString, int x, int y ); The errors: error C2664: 'OutputText' : cannot convert parameter 1 from 'char (*)[20]' to 'char *' error C2664: 'push_back' : cannot convert parameter 1 from 'char' to 'const char (&)[20]' Help me please! [edited by - dovyman on December 24, 2002 3:06:30 PM] [edited by - dovyman on December 24, 2002 3:10:06 PM]

Share this post


Link to post
Share on other sites
Advertisement
You should use std::strings:

  
std::vector<std::string> stringVector;

void WriteBoxText()
{
std::vector<std::string>::iterator iter;
for(iter=stringVector.begin(); iter!=stringVector.end(); ++iter)
g_Font_small.OutputText(iter->c_str(), 100, 100);
}

void AddLine(const std::string& string)
{
static int x = 1;
if(x == 10)
{
std::vector<std::string>::iterator iter;
iter = stringVector.begin(); // begin(), not end()

stringVector.erase(iter);
x--;
}

stringVector.push_back(string);
x++;
}


HTTP 500 x7...

HTH

Share this post


Link to post
Share on other sites

  • Advertisement