Hello, i am trying to read the contents of a txt file that will store a variable. this txt file will only contain one or string number. so far i have gotten the program to store numeric values but i am unable to store a string.
the below code reads from a txt file which only has the number "100" in the first line. it stores 100 into the variable x.
i have edited the above code to save the name"John" in variable x. but it does not work. i really need the program to read and save hex values such as 3E8. I am using string incorrectly. any help offered would be appreciated.
thanks for you reply, but i tried running the program but it still does not work. i am using borlan c++. I am not allowed to use another compiler.. can you think of anything else that may be causing the problem.
I'm puzzled as to why you use a while() loop to read a single value.
But that aside, are you sure that the file is actually opened correctly?
After the open() statement, you could check good() or is_open() to verify that the file was successfully opened. Use a cout message to show the status.
Hi dude I tried to look again for you ...I noticed that
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
x=n; // you assign n to x
cout<<n; // you cout n...did you mean x? Or am I mistaken?
Also you don't really need to assign it it anything if you input n just cout << n you don't have to assign it to another variable.
Maybe it will help or maybe I'm wrong take it with a grain of salt I tried.