request for member ‘c_str’ in ‘str’, which is of non-class

14,675

str is an array of string:

 string str[10];

so you can't call str.c_str(). You need to call it on one of the elements of str, i.g. with an index:

str[i].c_str()
Share:
14,675
Admin
Author by

Admin

Updated on November 02, 2022

Comments

  • Admin
    Admin over 1 year
    main.cpp:561:80: error: request for member ‘c_str’ in ‘str’, which is of non-class type ‘std::string [10] {aka std::basic_string<char> [10]}’
       displayFont.showHighscore[i] = TTF_RenderText_Solid(displayFont.menuFont,str.c_str(), displayFont.colorText);
    

    Hi all!

    According this function, this shows a ranking with data that is retrived from a member class. Also this used ttf content from another class (displayFont). When I compile this, said an error. I leave the code:

    void showHighscore() {
    
        displayFont.menuFont = TTF_OpenFont("fonts/Lanehum.ttf",25);
        displayFont.colorText = { 255, 255, 255 }; // Add content
    
        stringstream texting[10]; // Variables
        string str[10];
        SDL_Rect posHighscore[10];
    
        for (int i = 0; i < 10; i++) {
            texting[i] << i << "#    - " << dat.topScore[i];
            str[i] = texting[i].str();
            displayFont.showHighscore[i] = TTF_RenderText_Solid(displayFont.menuFont,str.c_str(), displayFont.colorText); // OUTPUTTING ERROR :/
            posHighscore[i].x = 50; 
            posHighscore[i].y = 50 * (i+1);
        }
    
        while (true) {
            for (int i = 0; i < 10 ; i++) {
                SDL_BlitSurface(displayFont.showHighscore[i],NULL,screen,&posHighscore[i]);     
            } // Show the rendered text
    
            SDL_Flip(screen);
            SDL_Delay(5000);
            break;
        }
    }