Hi!
Below is a part of my code, and whenever I this part of code starts executing, an error ocurrs! I get this error: click here to get a error screenshot whenever I add the ios:app parameter after the userScore.csv part, except that my file isn't QueryLanguage.Lib.dll, but rather something else.
So the only change I make is having ofstream userScore ("userScore.csv", ios:app); instead of just ofstream userScore ("userScore.csv");. Strangely, the new addition to my file's content is appended! But I get the error anyway and I must quit the program.
CODE:
// Save the user score for a subject to a file
string userName = marshal_as<string>(lblStudent->Text);
string scoreS = to_string(score);
subject = subject;
ofstream userScore ("userScore.csv");
userScore << userName << "," << subject << "," << scoreS << endl;
userScore.close();
// Get other results
ifstream userScoreRead ("userScore.csv");
string userResult;
while (getline(userScoreRead, userResult))
{
if (subject == "General")
{
if (extractWord(1, userResult) == userName && extractWord(2, userResult) == "CS323")
{
lblCourse2->Text = "CS323: " + marshal_as<String^>(getLastWord(userResult));
}
if (extractWord(1, userResult) == userName && extractWord(2, userResult) == "IT250")
{
lblCourse3->Text = "IT250: " + marshal_as<String^>(getLastWord(userResult));
}
if (extractWord(1, userResult) == userName && extractWord(2, userResult) == "NT310")
{
lblCourse4->Text = "NT310: " + marshal_as<String^>(getLastWord(userResult));
}
// If a subject can't be found
istreambuf_iterator<char> eof;
string searchTerm = userName + ",CS323";
if (eof == search(istreambuf_iterator<char>(userScoreRead), eof, searchTerm.begin(), searchTerm.end()))
{
lblCourse2->Text = "CS323: N/A";
}
searchTerm = userName + ",IT250";
if (eof == search(istreambuf_iterator<char>(userScoreRead), eof, searchTerm.begin(), searchTerm.end()))
{
lblCourse3->Text = "IT250: N/A";
}
searchTerm = userName + ",NT310";
if (eof == search(istreambuf_iterator<char>(userScoreRead), eof, searchTerm.begin(), searchTerm.end()))
{
lblCourse4->Text = "NT310: N/A";
}
}
if (subject == "CS323")
{
if (extractWord(1, userResult) == userName && extractWord(2, userResult) == "General")
{
lblCourse2->Text = "General: " + marshal_as<String^>(getLastWord(userResult));
}
if (extractWord(1, userResult) == userName && extractWord(2, userResult) == "IT250")
{
lblCourse3->Text = "IT250: " + marshal_as<String^>(getLastWord(userResult));
}
if (extractWord(1, userResult) == userName && extractWord(2, userResult) == "NT310")
{
lblCourse4->Text = "NT310: " + marshal_as<String^>(getLastWord(userResult));
}
// If a subject can't be found
istreambuf_iterator<char> eof;
string searchTerm = userName + ",General";
if (eof == search(istreambuf_iterator<char>(userScoreRead), eof, searchTerm.begin(), searchTerm.end()))
{
lblCourse2->Text = "General: N/A";
}
searchTerm = userName + ",IT250";
if (eof == search(istreambuf_iterator<char>(userScoreRead), eof, searchTerm.begin(), searchTerm.end()))
{
lblCourse3->Text = "IT250: N/A";
}
searchTerm = userName + ",NT310";
if (eof == search(istreambuf_iterator<char>(userScoreRead), eof, searchTerm.begin(), searchTerm.end()))
{
lblCourse4->Text = "NT310: N/A";
}
}
if (subject == "IT250")
{
if (extractWord(1, userResult) == userName && extractWord(2, userResult) == "CS323")
{
lblCourse2->Text = "CS323: " + marshal_as<String^>(getLastWord(userResult));
}
if (extractWord(1, userResult) == userName && extractWord(2, userResult) == "General")
{
lblCourse3->Text = "General: " + marshal_as<String^>(getLastWord(userResult));
}
if (extractWord(1, userResult) == userName && extractWord(2, userResult) == "NT310")
{
lblCourse4->Text = "NT310: " + marshal_as<String^>(getLastWord(userResult));
}
// If a subject can't be found
istreambuf_iterator<char> eof;
string searchTerm = userName + ",CS323";
if (eof == search(istreambuf_iterator<char>(userScoreRead), eof, searchTerm.begin(), searchTerm.end()))
{
lblCourse2->Text = "CS323: N/A";
}
searchTerm = userName + ",IT250";
if (eof == search(istreambuf_iterator<char>(userScoreRead), eof, searchTerm.begin(), searchTerm.end()))
{
lblCourse3->Text = "General: N/A";
}
searchTerm = userName + ",NT310";
if (eof == search(istreambuf_iterator<char>(userScoreRead), eof, searchTerm.begin(), searchTerm.end()))
{
lblCourse4->Text = "NT310: N/A";
}
}
if (subject == "NT310")
{
if (extractWord(1, userResult) == userName && extractWord(2, userResult) == "CS323")
{
lblCourse2->Text = "CS323: " + marshal_as<String^>(getLastWord(userResult));
}
if (extractWord(1, userResult) == userName && extractWord(2, userResult) == "IT250")
{
lblCourse3->Text = "IT250: " + marshal_as<String^>(getLastWord(userResult));
}
if (extractWord(1, userResult) == userName && extractWord(2, userResult) == "General")
{
lblCourse4->Text = "General: " + marshal_as<String^>(getLastWord(userResult));
}
// If a subject can't be found
istreambuf_iterator<char> eof;
string searchTerm = userName + ",CS323";
if (eof == search(istreambuf_iterator<char>(userScoreRead), eof, searchTerm.begin(), searchTerm.end()))
{
lblCourse2->Text = "CS323: N/A";
}
searchTerm = userName + ",IT250";
if (eof == search(istreambuf_iterator<char>(userScoreRead), eof, searchTerm.begin(), searchTerm.end()))
{
lblCourse3->Text = "IT250: N/A";
}
searchTerm = userName + ",General";
if (eof == search(istreambuf_iterator<char>(userScoreRead), eof, searchTerm.begin(), searchTerm.end()))
{
lblCourse4->Text = "General: N/A";
}
}
}
userScoreRead.close();
lblCourse2->Visible = true;
lblCourse3->Visible = true;
lblCourse4->Visible = true;
showTabPage(tabResults);
Any solutions?
Thanks!