I've spent a few hours on this looking up tutorials and other posts about this, but can't find anything to help me.
What I want to do is get input from the user, such as a filename, but echo what they've typed so far on the window.
Here's a simple version of what I got so far:
In game loop:
//outside of event loop..
std::string inputString;
//...inside loop
if (GUIevent.type == sf::Event::TextEntered){
if (GUIevent.text.unicode < 128){
inputString += static_cast<char>(GUIevent.text.unicode);
}
}else if(GUIevent.type == sf::Event::KeyPressed){
if(GUIevent.key.code == sf::Keyboard::BackSpace){
if(!inputString.empty()){
inputString.erase(inputString.size() - 1);
}
}
//...end loop
In draw function:
//Declaration:
sf::Text currentText;
//Function
void GUI_loadFile::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
if(!inputString.empty()){
const sf::String newString(std::string(inputString));
currentText.setString(newString); //causes error here!
target.draw(currentText);
}
}
So essentially the draw function is called every iteration of the loop and the events above edit the string that gets cast as a sf::String and drawn as a sf::Text object.
The error reads :
error: passing 'const sf::Text' as 'this' argument of 'void sf::Text::setString(const sf::String&)' discards qualifiers [-fpermissive]|
error: conversion from 'const sf::String(std::string) {aka const sf::String(std::basic_string<char>)}' to 'const sf::String' is ambiguous
Is there anyway to get the edited `std::string` into a `const std::string` or `const sf::String` so I can pass it to the text object? I've messed around with sstream and ostreams but couldn't get that to work either.