Or just read each line into a string, then deal with that string once it is in memory.
Code:
#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
using namespace std;
int main()
{
string myInputLine;
cout<<"How many groups?"<<endl;
// Only use this line for reading from cin
// Then use whatever seems best to extract information from that line
// Two examples of how to do it follow.
// Then all that fflush(stdin) and cin.ignore() nonsense just goes away.
getline(cin,myInputLine);
istringstream is(myInputLine);
int nGroup;
is>>nGroup;
string delGroup;
string delTeams;
for(int i=0;i<nGroup;i++)
{
cout<<"What name for Group "<<i+1<<"?"<<endl;
getline(cin,myInputLine);
// 1. Avoid at all possible any use of C-style char arrays
// 2. If you must use them, avoid lying about the size of the array
// char GrpName[300];
// cin.getline(GrpName,30); // should have been sizeof(GrpName)
string FileName=myInputLine;
}
cout<<"Do you want to clean up all files created ?(y/n)"<<endl;
getline(cin,myInputLine);
char YesNo = myInputLine[0];
if(YesNo=='y'||YesNo=='Y')
{
cout<<"deleting all files created"<<endl;
cout<<"deleting Group files..."<<endl;
system(delGroup.c_str());
cout<<"deleting Team files and Team Extended files..."<<endl;
system(delTeams.c_str());
}
return 0;
}
Mixing a whole bunch of input styles is just asking for trouble. Then you end up with all sorts of random hacks to clean up the mess.