How to label the first input of user as 1 ,second input 2, third input 3..etc by using ofstream append? Everytime when I used terminal to run it
e.g.
./addcontact.cpp name1
./addcontact.cpp name2
so that inside dat file it will has number of sequence in front of new name?
e.g. in dat file
1 name1
2 name2
3 name3
int main(int argc, char* argv[])
{
int i =0;
vector <string> input;
Contact addingname;
if (argc == 2)
{
input.push_back(argv[1]);
cout<<"Ok, contact "<<i+1<<" "<<input.at(i)<<" added "<<endl;
string newname = input[i];
int size= input[i].size();
for(int j = 0; j<size; j++)
{
if (isalpha(newname[j]))
{
addname(newname);
;}
}
void addname(string name)
{
i++;
ofstream myfile(CONTACTS, ios::app);
if (myfile.is_open());
{
myfile<<i<<name<<endl;
myfile.close();
}
}
I used these codes but they are not working? and gave me undesired output...any idea how to modify it?