SFML std::length_error 在 window.setTitle

SFML std::length_error on window.setTitle

我用 SFML 开始了一个项目,我想在 window 标题上显示 fps 和勾号,但这不起作用:

string title =  to_string(frames) + " fps, " + to_string(ticks) + " ticks";
window->setTitle(title);

我得到这个错误:std::length_error

我已经尝试过了并且成功了:

window->setTitle("5454,grgvfvfvfvfvfvffffffffffrtrrh");

fps 和 frameint

所以我不明白,如果有人有答案。

exception description 是这样说的:

Defines a type of object to be thrown as exception. It reports errors that result from attempts to exceed implementation defined length limits for some object.

This exception is thrown by member functions of std::basic_string and std::vector::reserve

在我看来,您正在使用一个具有奇怪限制的奇怪编译器。

你好,我找到了我的问题,但我不明白是什么,但我只需要做:

string title =  to_string(frames) + " fps, " + to_string(ticks) + " ticks";
window->setTitle(title.c_str());

".c_str()" 解决我的问题