0

So basically we'll just say that, for example, the user inputs 'As' and it is set to variable 'A'.
I have an input .txt file that has a list of these characters (it's for figuring out molecular geometry) so somewhere in the text file it says
'Arsenic As 5'
I want to have my program run through the input file, looking for the contents of string 'A,' retrieve the 5, and assign it to another variable, 'v.' How could i go about that?

3
Contributors
5
Replies
47
Views
2 Years
Discussion Span
Last Post by SumTingWong59
Featured Replies
  • Open input file. Get each word one at a time. If word == A: Get the next word v = that next word Read More

  • 1

    The file is not huge (molecules); consider reading the entire file into a data structure in memory. Perform the look ups in memory, and if the data is modified, write it back into the file at the end. For instance: http://coliru.stacked-crooked.com/a/30d9483adc21fb9a Read More

  • ` inData.get(A);` You're trying to feed the ifstream class function `get` a `string`. It doesn't take a `string`. http://www.cplusplus.com/reference/istream/istream/get/ You can see there what paramters the `get` function you're trying to use can take. Read More

1
Open input file.
Get each word one at a time.
If word == A:
    Get the next word
    v = that next word
0

hey Moschops, if you have time do you think we could private chat and you could help walk me through this? I understand what I need to do I'm just having a lot of trouble understanding how to go about it

Edit: and i switched it to inData >> A >> B >> b;, that should work right?

Edited by SumTingWong59

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.