1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

C++, String

Discussion in 'Software Development' started by calculus87, Sep 11, 2003.

Thread Status:
Not open for further replies.
  1. calculus87

    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
     
  2. Guy

    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
     
  3. calculus87

    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
     
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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/164035

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice