#include <iostream>
#include <fstream>
usingnamespace std;
#define NEWLINE '\n'
#include <windows.h> // needed for Sleep(millisec)
int main ()
{
system("color 02");
string response;
string name;
ifstream ifName;
ofstream noName;
ifName.open("Names.txt");
if(!ifName.is_open())
{
if (!ifName.eof())
{
getline(ifName, name);
cout << "Welcome back, " << name << endl;
ifName.close();
}
else
{
ifName.close();
noName.open("Names.txt");
cout << "Please enter your name: ";
getline (cin, name);
noName.close();
}
}
cout << NEWLINE;
cout << "What can I do for you? " << endl;
getline (cin, response);
Sleep(2000);
return 0;
}
I believe that I do. I have to leave for a couple hours but I'll look over it again when I get back. I believe everything should be right. Can I get your opinion?
This is really frustrating. I copied and pasted your code into mine and I had to change a couple minor things and then it worked. It worked exactly how I wanted it to. I tried copying the slightly altered code from my test file to my main file but now neither want to work.. God, I hate this thing.
The "What can I do for you? " is suppose to be outside all the brackets. Plus, if I straight copy and paste your code now and into a brand new file, it only says Cannot open file.
Stick with my code. If you put what can I do for you outside the brackets, then it will always run regardless of whether or not the file opens and you'll never know when it doesn't. As for the file, you need to create a text file with notepad and save it as Names.txt
So that was the problem. I erased the old file "Names" and changed it to "Namefile" within the code but I assumed that it would be automatically created.
=P Thank you!!! =D =D =D =D
Do you know how I'd be able to update my program where it'd effect its "copies", like I'd like to send it to a friend so he can check it out?
So if I add/change my code, I don't have to resend my program to him again and again?
I've looked up on google about updating your c++ program and its said some things about Visual 2010 so i downloaded it but i guess some things r different on visual than codeblocks.. Thank you so much.
My next task is to loop it back to the "Please enter your name: " if the user inputs "erase/reset name"
and then being able to access My Documents and the like with user inputs.
If you want something interesting like that, you could create a text file that maintains all document names and you could access it that way. I might just do something like this now. If you really want to have some fun, work on making it into a user/password program with individual account text files.
dam, you're getting way ahead of me; for now. only started learning last friday. but i will keep that in mind.
or is there a way that I can search all my files based on a search within my program, like u would do using 'Run'?
Probably. I just think it would be easy to use a simple file. If I could figure out how to make the file so it is unable to be edited, then I would be on my way. All I can do with files for now is read and write. If I could get a GUI to interact with the file, then I'd have it made.