Hey guys, so I'm doing C++ at my school but it's independent study and thus I've been making up my own projects. On this particular one I've hit a roadblock. Currently it allows grade data to be inputed for an array of student objects and then have it later viewed (for the duration of runtime). Each array number contain's its own grade data because it's suppose to represent a student and so the user has use numbers which isn't ideal. What I want to do is make it so the user can input a student's name and then that would store the grade data. I'm not really sure as to how to go about this and would appreciate any advice.
Also this isn't vital but it'd be great if the grade data could save itself for later viewing even after the program has closed.
Hmmm, I put the map and string declarations below my comment of "//Declares variables used in functions" and it says "name" is an undeclared identifier. "String" didn't turn blue nor did "map" so I'm assuming something is wrong with the compiler?
Huh? They don't belong into the class. It could get a name member, but that's obviously separate from the input variable.
The only things that belong into a class are attributes that describe an instance of that class (a student) and operations (methods) you can perform on a student (and sometimes static members).
"String" didn't turn blue nor did "map" so I'm assuming something is wrong with the compiler?
Editor, not compiler. And no, string and map aren't builtin types, so editors don't highlight them in the same color as int, double etc.. std::string and std::map are classes that are part of the C++ standard library.
Oh, ya that doesn't make sense. So I put them in main, (is that right?), and it compiled sort of but stopped at getline so I did this "std::getline(std::cin, name);" and that sort of worked but now it's saying
"Unhandled exception at 0x004015aa in arrays.exe: 0xC0000005: Access violation reading location 0xc982d268."
and I have to end the program with task manager :/
And thanks a lot for the explanation that clears some things up.
There isn't much room for access violations when using maps, so... post your new code.
Also, I wouldn't say something works when it causes an access violation. It's very much broken.
Awesome! That made it work thank you so much Athar, one thing I had to do though was "cin >> name;" instead of the getline bit because it was passed over when I repeated the loop. Is there a reason for this?
If you are using ` cin >> someVar ' in your code before a call to getline() the carriage return is probably still in the buffer so getline extracts it and goes on about its merry way. Try cin.sync() before calling getline().