This is a bizarre error that I have never seen before, and do not know how to fix it. The crash occurs on
na = m
Here is the relevant code. The line in question is marked with *:
In Main:
#include <cstdlib>
#include <iostream>
#include "stu.h"
#include <string>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
stu stu;
int score[2];
std::string name;
std::cout <<"enter name:";
std::cin >> name;
//THIS IS AN EDIT IN AFTER SEEING THAT A IMPORTANT ERROR POINT WAS NOT SHOWN TO THE FIRST COUPLE REPLY
************************************************************
//THIS IS CAUSING THE PROBLEM WHEN I COMMENT IT OUT THE PROGRAM WORKS
std::cout << "enter score 1:";
std::cin >> score[0];
std::cout << "enter score 2:";
std::cin >> score[2];
std::cout << "enter score 3:";
std::cin >> score[3];
*************************************************************
stu.setname( name );
// ...
}
In stu.ccp
:
void stu::setname(std::string m)
{
std::cout <<"1";//<--to find where the code was crashing
na = m; // *** the crash
std::cout <<"1";
}
In stu.hpp
:
class stu
#include <string>
{
public:
stu();
void setname(std::string);
std::string getname();
void settest(int, int,int);
void display();
private:
std::string na;
int score[2];
};