【问题标题】:How to pass a string into glutCreateWindow() function? [closed]如何将字符串传递给 glutCreateWindow() 函数? [关闭]
【发布时间】:2019-08-29 19:53:39
【问题描述】:

我正在从一个文件中读取一个名称,然后我用它来命名窗口。但是,它不允许我这样做,因为它需要一个 ASCII 字符串。但是我可以直接做这样的事情

glutCreateWindow("StackOverflow"). 

这不也是ASCII字符串吗?为什么我能做到这一点,但不能这样:

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

有没有办法投射“x”来满足我的需要?

【问题讨论】:

  • glutCreateWindow的参数类型为const char *。所以它必须是const char *x = "stack";glutCreateWindow(x);。或std::string x = "stack";glutCreateWindow(x.c_str());。见std::string。但那是非常基本的 c++。

标签: c++ opengl glut


【解决方案1】:

使用std::string::c_str() 方法:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多