c++ - Not getting desired output for cin.getline(), -


i have started c++ today , have looked through many feeds on topic. while searching found function called ignore helped. initial problem input being skipped when running. found due \n still being in buffer used cin.ignore() function flush out. however, still not getting output desire. here code:

{

    time_t current;      char event[30];     char details[256];      char outfilename[21];     cout<< "enter name of file hold input.[20 character max]:  ";     cin>>outfilename;      ofstream outfile(outfilename);      cout<< "event: ";     cin.getline(event, 30, '\n');     cin.ignore();     outfile<< event<< '\n';      cout<< "details: ";     cin.getline(details, 256, '\n');     cin.ignore();     outfile<< details<< '\n';      current = time(null);     outfile<< ctime(&current); 

}

for output, first line black, second line lists should on first line , missing first letter, third line fine system time.

put cin.ignore after inputting name of file. carriage return cin>>outfilename; being absorbed next cin.

also i'm not sure if ignore right command use here. if doesn't work try cin.clear() or cin.sync(). take grain of salt, i'm still learning c++.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -