write from a .txt file with a cout function

Write your question here.
I have a simple little code I'm working on as a learning tool. It prompts the user for a password. It then logs the password used to unlock the program with date and time into a .txt file. It then goes on to let user use a simple calculator function. What I would like to do is create like an admin pass word that gets all the info in that file to appear in the cmd window using a cout function. I have been trying the examples I found here

http://www.cplusplus.com/forum/beginner/120813/

But when I get to line 10. I get the wavy red line under the word data. The compiler says "expecting a ;". Then all mentions of the word data in the rest of the code exampled in link above gets same wavy red line and compiler says "data is undefined". I'm looking for examples of how to code this so I may include it into my little project.
If you want examples, it's better to work from the tutorial.
http://www.cplusplus.com/doc/tutorial/files/

In the thread you linked to, the header for std::string is missing:
 
#include <string> 
I didn't know there was a header for strings. Thank you for that info. I never included it into my build. This may have been my problem. Also thanks for the link.
I have tried to inject the example into my code but I'm getting the same type of error. When I include the example given from the tutorial the first line is

String line;

When I type it in I get the same red wavy line under line and compiler says " expected a ;"
At the point of getline it to has wavy red line and says "no evidence of overload function getline matches the argument list"
Then just after that in same line the entry myfile, line there is that same red line under the word line and compiler says identefier "line is undefined"
I I cluded the header for string. I'm not sure what's wrong. Any suggestions?
Did you write String line; or string line;?

(You should have the latter.)
Its all typed in lower case. I have the proper format. All of my post are done from phone. The keyboard auto caps the start of a new sentences. As for the coding its all typed in lowercase except for the name of the .txt file name but its proper because its name is capped in the write out to file portion and it does not cause an error.

Found the problem. In the begining of my coding I used int string for the codes. I changed that to int codes and all wavy lines disappeared. Stupid noob mistake. I was under the assumption that I had defined int as string but naming some thing else string wood not become a problem if the sections were seperated by {}`s. Thank you all for the help though.
Last edited on
Topic archived. No new replies allowed.