I have just started getting into SFML and Visual studio as well . I have always worked on turbo c++ . I am not sure I understand the very first code that I have come across while getting into SFML . Here is the program..

#include<iostream>
#include<SFML\System.hpp>


int main()
{
    sf::Clock Clock;

    sf::Sleep(0.1f);

    while (Clock.GetElapsedTime() < 5.f)
    {
        std::cout << Clock.GetElapsedTime() << std::endl;
        sf::Sleep(0.5f);
    }

    return 0;
}

I know this is probably the most basic thing ever . But I have a few questions .

Q1. What is 'sf' ? Is it a class ?
Q2. Why is the operator '::' being used here ?
Q3. Is 'Clock' a class as well?
Q4. what does the 'f' represents in sleep(0.5f)?
Q5. Why can't we use 'getch()' in visual studio? (I am a beginner)

I have just started getting into SFML and Visual studio as well

Good. TC is quite old. New IDEs are way better on so many levels.

Q1. What is 'sf' ? Is it a class ?

It is a namespace.

Q2. Why is the operator '::' being used here ?

Answer for Q1 would cover this i suppose.

Q3. Is 'Clock' a class as well?

Clock is an object of sf::Clock.
Example

Q4. what does the 'f' represents in sleep(0.5f)?

0.5 is double by default. o.5f is float. You might want to read this

Q5. Why can't we use 'getch()' in visual studio? (I am a beginner)

I am not sure about that(MSDN link). But do NOT use it unless there is no other way. This is not a standard C function. Use getchar instead

EDIT:
For Q1, since you already seem to have Visual Studio, just hover the mouse over whatever you don't know what it is, in this case, a namespace. The IDE tells you what it is(at least in VC++ 2010). Also, there are plugins like Visual Assist that can be really helpful while reading code.

Edited 4 Years Ago by myk45

Comments
Thank you so much for the help!

Q1. What is 'sf' ? Is it a class ?

As per myk45's post, it's a namespace, in the same way that std is a namespace. If you're not up to speed with namespaces, a quick check in your C++ reference book should tell you what you need to know.

Q2. Why is the operator '::' being used here ?

In addition to what myk45 said, it's a scope resolution operator. In conjunction with the namespace name it identifies that Clock is from the sf namespace, rather than any other possible Clock that might exist in a different namespace.

Q3. Is 'Clock' a class as well?

Because it's in the SF namespace and part of SFML, if you want to know more about Clock, you should check out the SFML documentation.

Q4. what does the 'f' represents in sleep(0.5f)?

See myk45's post.

Q5. Why can't we use 'getch()' in visual studio? (I am a beginner)

In addition to what myk45 said, each time someone uses getch() a kitten dies.

Some of your questions above relate to standard C++, some are SFML-specific. It'd be worth familiarising yourself with the SFML documentation and checking out any SFML-specific support forums.

This article has been dead for over six months. Start a new discussion instead.