Message Board
Message Board > C/C++ > reading from txt file help with sdl |
June 3, 2013, 07:06 | |
DoctorN
Whiskered 91 posts |
Code: //Render the text string line; ifstream myfile ("text.txt"); if (myfile.is_open()) { while ( myfile.good() ) { getline (myfile,line); cout << line << endl; } myfile.close(); } else { cout << "Unable to open file"; } message = TTF_RenderText_Solid( font, line, textColor ); //If there was an error in rendering the text if( message == NULL ) { return 1; } at the moment there is only one line of code in the .txt file Quote: text and if you are wondering, message is an SDL_Surface. I get the error Quote: Error 1 error C2664: 'TTF_RenderText_Solid' : cannot convert parameter 2 from 'std::string' to 'const char *' c:\users\my name lol\documents\visual studio 2008\projects\thetest-text\thetest-text\main.cpp 49 what do you think will help me? because I would like to turn message into an array so that I can have multiple messages (to ease up code). thanks ____________ |
# |
June 3, 2013, 16:24 | |
DTM
Earthling! 823 posts |
line is a std::string object, but TTF_RenderText_Solid wants a C style string (which is just an array of chars). use the c_str() method of string objects to get a char array: message = TTF_RenderText_Solid( font, line.c_str(), textColor ); http://en.cppreference.com/w/c … ng/basic_string http://en.cppreference.com/w/c … ic_string/c_str ____________ :o |
# |
June 4, 2013, 03:31 | |
DoctorN
Whiskered 91 posts |
how can I do an array of sdl_surface* message? I get the error "cannot convert from int to sdl_surface* [16]" thanks EDIT: NEVERMIND I FIXED IT Code: SDL_Surface *message[12] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; works [Edited on June 4, 2013 by DoctorN] ____________ |
# |
Message Board > C/C++ > reading from txt file help with sdl