>> std::string groupname;
Using a C++ string instead of C style strings is an improvement.

>> cout << "No more than 30 characters, please." << endl;
I don't think the check for 30 characters is necessary, though, as it was almost certainly only originally needed to avoid overstepping the character array bounds.

>> if(std::getline(cin,groupname) > 30)
This won't work, getline does not return the number of characters read. As I mentioned above, the > 30 is probably not necessary anyway, so if(std::getline(cin,groupname)) should be good.

>> ofstream group;
Moving a variable to a larger scope unnecessarily is not an improvement, IMO. There will be no noticeable performance benefits, and keeping the variable scope limited is better design here.

>> group.close();
You would also want to clear() any failbits at the end of the loop just in case, although this would be more likely to cause a problem on an input file. Of course, moving the variable declaration back inside the for loop scope would make the close() automatic and a clear() unnecessary.

>> group.open(groupname);
This should be group.open(groupname.c_str()); since filestreams take C style strings as arguments to open.

12-19-2006

CodeMonkey

It seems you replied to my code as I was editing it. Anyway, all of your comments did apply.

12-21-2006

vearns

Hello,
why when i inserted group name without space,the program suddenly quit.

>> why when i inserted group name without space,the program suddenly quit.
Maybe because your code looks for the first space in the group name when it uses the code:

Code:

int indexTeam=copysTeam.find_first_of(' ');

But if there is no space that will return -1. You then call erase with -1 as an argument, which might be crashing the program. YOu should compare indexTeam with string::npos, and only erase if they is not equal.

>> fflush(stdin);
Why is this there? Besides being bad practice in C, there is no reason to use it in C++. The first fix suggested, adding cin.ignore() after the call to cin>>nGroup; is the better way to go.

12-21-2006

vearns

fflush(stdin);

the function is same with cin.ignore()

i still have no idea to use string::npos

maybe someone can show me some example.

12-21-2006

Daved

>> the function is same with cin.ignore()
No, it is not the same. Use cin.ignore().

>> i still have no idea to use string::npos
Do you know how to compare two values in an if statement? Make an if statement that compares indexTeam and string::npos and enters the if block if those two values are not equal. How would you do it if I said to compare indexTeam to -1? The code would be the same except you'd replace -1 with string::npos.