Hi guys, actually i'm trying to write a program which will write the user input into dat file and start to count the user input from 1. When user inputs second value,
it will go to other line and put 2 in front of user value. Any idea how to modify the below codes in order to make it like a counter that will put 1 at first input and then 2 at second input? Thanks!! Need to use this in project...:S
int addname(string name)
{
char aline;
int a = 1;
ifstream myfile;
myfile.open (CONTACTS);
if (myfile.is_open())
{
while (myfile.good())
{
aline = myfile.get();
if (aline == '\n')
{
a++;}
}
myfile.close();
}
else
{
ofstream myfile(CONTACTS, ios::app);
myfile<<a<<name<<endl;
myfile.close();
}
return a;
}