kullanma: MSVS2012C++: Erişim ihlali yazma yeri
Kod
elemalg.h
#include <vector>
#include <string>
#include <fstream>
class ElemAlg
{
private:
std::string difficultlyLevel, question, answerToRead;
std::vector<std::string> questions, answers;
std::vector<std::string> GetQuiz(int);
};
elemalg.cpp
#include "elemalg.h"
std::vector<std::string> ElemAlg::GetQuiz(int difficulty)
{
if (difficulty == 1) { difficultyLevel = "algE"; }
if (difficulty == 2) { difficultyLevel = "algM"; }
if (difficulty == 3) { difficultyLevel = "algH"; }
if (difficulty == 4) { difficultyLevel = "algVH"; }
std::ifstream fin(difficultyLevel + ".txt");
while (std::getline(fin, question)) { questions.push_back(question); }
fin.close();
std::ifstream fin2(difficultyLevel + "Answers.txt");
while (std::getline(fin2, answerToRead)) { answers.push_back(answerToRead); }
fin2.close();
return questions;
}
MathTutor.cpp
#includes etc
ElemAlg *ea;
ea->GetQuiz(1);
GetQuiz
yöntem
difficultyLevel
if
fonksiyonunu vuran
derleyici en kısa sürede ... bir işlenmeyen özel durum ve Erişim ihlali yazma konumunu atar.
if
işlevlerini kaldırırsam ve aynı sorunu test etmek için algE olarak difficultyLevel
tanımladım.
Tamamen difficultyLevel
kaldırmak ve kod while döngüsü vurur kez sadece "algE.txt"
ve "algEAnswers"
sonra aynı sorun olsun ama farklı hafıza yerde dosyasını açarsanız.
tam 'difficultyLevel' nedir? –
Parametre, işlev içinde bir savrulma ile doğrulanmalı ve dışlanmamalıdır. Sorular küresel bir değişken ise, neden geri göndermeye çalıştığınızı bilmiyorum. –
[MCVE] (http://stackoverflow.com/help/mcve) veya gerçekleşmedi. – Angew