The issue is that your lp instance is infeasible so the call to .optimize() results in an infeasible status. From your code
model.write("test2.lp");
model.optimize();
model.write("forum2.sol");
if(model.get(GRB_IntAttr_Status) != GRB_OPTIMAL){
cout << "niet optimaal " << endl;
}
You are writing a .sol file before you check for success. Gurobi gets the 'X' attributes from the variables when it writes a .sol file. If the optimization fails, the 'X' attributes aren't available and an exception is thrown. You should make sure that gurobi has a solution before you write a .sol file, or get many attributes, including 'X', 'Pi' and 'ObjVal'. The OPTIMAL status codes assures you that that there is an available solution, but codes like SUBOPTIMAL also indicate that there is a solution available and others like TIME_LIMIT, NODE_LIMIT mean there might be a solution available. You can get the attribute SolCount to get a definitive indication that there is a solution available.
Your problem instance is infeasible because constraints (R1, R7, R13 imply you need at least 3 projects for students 1 and 2, but constraints (R19, R20) imply they can have exactly 1 project each. You can see this by using the IIS solver. In interactive gurobi you can get get an Irreducible Inconsistent Subsystem
m = read("test2.lp")
m.optimize()
m.computeIIS()
m.write("test2.ilp")