c++ string declaration

Shadow2531

[H]ard|Gawd
Joined
Jun 13, 2003
Messages
1,670
Just curious.

Is there a way to declare a string where the name of the string to be delcared is a value of another string?

Something like

string x = "bla";
string [value of x] = "4";

Basically, can you dynamically declare a string?

Thanks
 
Your best bet is probably to use a Map. Here is a quick example I found with google.
 
Thanks.

I just wanted to see if I could do something like this.

Code:
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {
    map<char,string> mymap;
    const string example = "color=red";
    mymap[example.substr(0,example.find("="))[0]] = example.substr(example.rfind("=") + 1 );
    cout << mymap["color"[0]] << endl;
}

Basically using a tokenizer and a loop, I could split up a string into keywords and be able to get the value of each keyword by referencing the keyword name via a map.

That really helped.
 
Back
Top