Search code examples
c++openglglut

How to pass a string into glutCreateWindow() function?


I am reading a name from a file which I then use to name the window. However, it will not allow me to do that since it requires an ASCII character string . I can however do something like this directly

glutCreateWindow("StackOverflow"). 

Isn't this also a ASCII character string? Why am I able to do this but not something like this:

string x = "stack";
glutCreateWindow(x);

Is there a way to cast "x" to meet my needs?


Solution

  • Use the std::string::c_str() method:

    std::string x = "stack";
    glutCreateWindow(x.c_str());