initializing variables in program

the title probably doesn't explain much but i want to know how to make variables during the program. for example in a program i want to have the player be able to create their own spells or add their own weapons to the game without having to edit the source code. i use sfml 2.0
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <map>
#include <string>

int main()
{
    std::map< std::string, int > variables ;

    std::string name ;
    int value ;

    while( std::cout << "variable name? " && std::cin >> name &&
            std::cout << "value? " && std::cin >> value )
    {
        variables[name] = value ;
    }

    for( const auto& pair : variables )
        std::cout << "name: " << pair.first << "  value: " << pair.second << '\n' ;
}
i tried that program and my compiler gave me these errors:

error: ISO C++ forbids declaration of 'pair' with no type [-fpermissive]|

error: range-based 'for' loops are not allowed in C++98 mode|

error: request for member 'first' in 'pair', which is of non-class type 'const int'|

error: request for member 'second' in 'pair', which is of non-class type 'const int'
Did you copy the entire program given and nothing else? The first error sounds like you are using namespace std; somewhere.

You should also set your compiler to compile in C++11 mode; which one are you using?
ok i got that program working thank you (THIS IS MY 100th Post)
Last edited on
Topic archived. No new replies allowed.