C++, String

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

calculus87

Thread Starter
Joined
Sep 4, 2003
Messages
34
Okay, quick question.
I have a text file with a list of words. I need each word to become a variable. So for example, I have in the text file: word1, word2, word3. Now I import them into a vector<string>. Now is there any way for me to overload that vector so as to make each word that I imported become a variable?

I could then say something like
word1 + word2 * word3. where each of these words is of type double.

Okay, thanks for your time and effort
Sincerely,
Ronald
 

Guy

Joined
Feb 19, 1999
Messages
260
Im pretty sure you can't do this but something similar that you could do is import them into a map, where the key is the string you import and the value is a double (you didnt say if this was an imported value or otherwise but it shouldnt matter).

example:

Code:
	map<string, double> myMap;
	myMap["Word1"] = 5.03;
	myMap["Word2"] = 2.0;
	myMap["Word3"] = myMap["Word1"] * myMap["Word2"];
	cout<<myMap["Word3"]<<endl;
hope this helps
 

calculus87

Thread Starter
Joined
Sep 4, 2003
Messages
34
Okay, thanks very much. You have given me a great idea. I will go ahead and develope this.
Thanks
Sincerely,
Ronald
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top