OKAY, so it's good to hear you are reading through a c++ book but sad to see you not comprehending some of the basics.
Integers are numbers. whole numbers, real numbers pure and simple. type int can hold a number that ranges from –2,147,483,648 to 2,147,483,647, unsigned int can hold a number 0 to 4,294,967,295 typically. There is nothing magical or hard to understand about integers, they are numbers, you can perform arithmetic with them, addition, subtraction, multiplication, division, modulus.
You are on the right track kinda with your loop statement. The thing you don't seem to realize is you already have a loop running. your while(window.open()) { ... } is a loop. So to give you a working example of how to add 1 to your gold amount each iteration through your main program loop and print it to the screen I give you this.
#include <iostream>
#include <SFML/Graphics.hpp>
#include <sstream>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "C++ Programming Test");
sf::Font arial;
if ( !arial.loadFromFile ( "arial.ttf" ) )
{ }
int goldamount = 0;
std::ostringstream myStream;
myStream << "You have " << goldamount << " Gold";
sf::Text goldtext;
goldtext.setFont ( arial );
goldtext.setCharacterSize ( 12 );
goldtext.setColor ( sf::Color::Yellow );
goldtext.setPosition ( 20, 20 );
goldtext.setString ( myStream.str () );
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw ( goldtext );
window.display();
goldamount++; //adds 1 to our goldAmount integer
myStream.str(""); //clears the string stream, correct way should be myStream.str(std::string())
myStream << "You have " << goldamount << " gold"; //restuff the stream
goldtext.setString(myStream.str()); //get string from the stream and set to text
}
return 0;
}