Hello guys!
I'm new at C++ (started yesterday) but I'm a fast learner and I think I got pretty far with this noob project! The only thing I need to do is to make C++ open my .txt file and the beta version of this application is done! By the way, I'm advanced in Java, so I think I'll get most of the directions you give me in C++.
Anyway enough chit-chat!
Here's my Data.cpp file:
#include <iostream>
#include <fstream>
using namespace std;
struct person
{
string firstName;
int age;
int phoneNumber;
};
int main()
{
ofstream data;
person people;
ifstream personExists("Person.txt", ios::out);
if(!personExists)
{
cout << "Persons name: <First name only>" << endl;
cin >> people.firstName;
cout << endl;
cout << "Persons age: " << endl;
cin >> people.age;
cout << endl;
cout << "Persons phone number: " << endl;
cin >> people.phoneNumber;
cout << endl;
cout << "Creating file: Persons.txt" << endl;
data.open("Person.txt");
data << "Name: " << people.firstName << endl;
data << "Age: " << people.age << endl;
data << "Phone number: " << people.phoneNumber;
data.close();
}
else
{
char answer;
cout << "You already got a data file, would you like to open it? <y = yes/n = no>" << endl;
cin >> answer;
cout << endl;
if(answer == 'y' || answer == 'Y')
{
data.open("Person.txt");
}
else if(answer == 'n' || answer == 'N')
{
exit(0);
}
else
{
cout << "Please answer my question!" << endl;
}
}
system("pause");
return 0;
}
I don't get any compilation errors, the only problem is that when you got the Person.txt file, and you chose the 'y' or 'Y' option nothing happens! It still won't open the. txt file..
So help will be appreticated A LOT! Thanks in advantage your friend: Benjamin Dahse ;P