View Full Version : Sticky: Need Simple C++ Help Right Away!!!
NeoNemesis
07-05-04, 15:23
I am need of C++ help for a very very simple question. I am trying to make a program and part of the program has to store variable data and input data that the user inputs (address book and username are some of the things that I have in this program) for the next time the program is opened. I'm using the ifstream and ofstream commands right now to store the data into a text file called username.txt for storing the users selected username (my goal is to make the program recognize the user by the data put into the username.txt by reading the file. So like every time the program loads it will say 'Welcome Desmond' if I decide to put my name in as the username. Well I have the storing part down and now I need to work on outputing the stuff from the text file back into the program. I'm using the standard ofstream to open the file and what not but when it outputs the person's username that they entered from the first registration part of the program it outputs it as 0xFFFFFFF. I have tried for days to get this to output the username in regular english and the damn thing won't work. I also want it to store the contents of the file when it opens it to a variable for the rest of the program to use it. So like later on in the program it can say like "Good Bye! Desmond' or something. Please help me since I really can't continue my program without this to work. This is probably so simple but I just learned C++ a couple days ago from picking up on a book I purchased a while back. So just keep that mind and I'm only 14 years old.
It would be appreciated if people email their responds to me at neonemesis4@Hotmail.com instead of posting here so that way I can be sure to read them. But you don't have to. :)
NeoNemesis
07-09-04, 11:14
Can someone please help me...
Hmm sounds like you are pointing to a place in memory instead of a file.....are you using pointers etc.?
Instead of using ofstream (output-filestream) for reading the file, then I suggest you use fstream. (includes both ifstream and ofstream).
CoderSource.net: text files using fstream (http://www.codersource.net/cpp_file_io.html)
CoderSource.net: binary files using fstream (http://www.codersource.net/cpp_file_io_binary.html)
C++ reference: fstream (http://www.cplusplus.com/ref/iostream/fstream/)
Btw. why has this become sticky ?
Btw. why has this become sticky ?Hehe didnt notice the "Sticky"-thing was part of the topic, nicely done :)
NeoNemesis
07-11-04, 12:27
No I'm not using pointers.
I will try fstream. I also have another question though. Can someone give me a simple example menu of where the user just has to press like one key and it goes to another function. Thanx. I want to redesign my menu right now because right now you have to press the key and then press enter and I'm wondering if I can just make it go to the function as soon as the person presses a key.
Can someone give me a simple example menu of where the user just has to press like one key and it goes to another function. Thanx. I want to redesign my menu right now because right now you have to press the key and then press enter and I'm wondering if I can just make it go to the function as soon as the person presses a key.
I guess in a C++ world the function would be:
cin.get() (http://www.cplusplus.com/ref/iostream/istream/get.html)
There also exist some non-standard functions (Though they are not supported on all compilers)
The usual DOS conio functions are getch(), getche(), and kbhit(). The
convention is to return the basic character set as a positive integer, an
unavailable character as end-of-file, and an "extended" character as a zero
integer followed by the extended character value on the next call. Extended
key-codes for a standard getch() would, of course, be implementation
defined. (The extended keycodes would be a bit of DOS revenge on Unix for
the whole text/binary issue; Unix libraries would need to provide some
mapping layer of keyboard escape sequences to extended keycodes).
getch() - unbuffered, invisible input
getche() - unbuffered input echoed to the screen
kbhit() - unbuffered, non-extracting input
vBulletin® v3.8.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.