Weird Error "This application has requested the runtime to terminate it in an unusual way"

Hello all,

First of all thank you for taking the time to help me, I really appreciate it. I would also like to start by saying I am extremely new to C++ and I am sorry if my code is ugly/inefficient. With that said I will move on to the problem.
I am asking about a very strange error I get while trying to run my code. The error message reads:
"This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information."

Since I made the program I am pretty sure that I am technically supposed to be the support team, so that throws that option out the window.

I have tried opening task manager and checking for a process that is keeping it from running correctly and ensured that all of my Microsoft c++ redistributables(spelled wrong) were up to date but to no avail.

From the research I have done, it seems that the: abort() function is what is causing my problem due to an unhandled exception or something.

From the looks of my code, can anyone determine the problem and maybe guide me in the direction of a solution?

I don't know if it matters but I am running Windows 7 Professional 64 bit on a dell laptop with a 2.7 ghz quad-core intel processer, 16 GB RAM, 750 GB HDD. And I am programing with bloodshed Dev-C++.


Source code from my 3 files:
main "sportData.cpp"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//brian whitsett
//date: 06/24/14
//lab7


#include <iostream>
#include "sportData.h"
#include "sportDataMethods.cpp"
#include <iomanip>
#include <cmath>          // Needed for the pow function
using namespace std;

int main()
{
    
    sportData players[100];//array of objects
    char runAgain = ' ';
    do
    {
   sportData sportData;
   sportData.execute(players);//call member method
                 
   	cout << "Enter More Player Stats?[Y|N]: ";
	cin >> runAgain;
	cin.ignore();
	runAgain = toupper(runAgain);
 system("pause");
 system("cls");    
 }
 while (runAgain == 'Y'); //end of do while
	
	return 0;
}//end of main
/*

*/


header: "sportData.h"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef sportData_H
#define sportData_H
#include <iostream>
#include <string>

using namespace std;



class sportData//class
{
      private:
              //private variables
      int iceTime; 
      int goals;
      int points;
      int penalties; 
      int assists;
      string playerName;
              
      public:
      ~sportData();//public member methods
      sportData();
      sportData(int iT, int g, int p, int pen, int a, string n);    
      void getStats();
      void writeStats();
      void displayStats();
      void execute(sportData players[]);
      int errorCode(double testDoubleVariable);
};
#endif



member methods: "sportDataMethods.cpp"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "sportData.h"
 #include <iostream>
 #include <string>
 #include <fstream>
 
 using namespace std;

 int howMany = 0;

sportData::~sportData()
{
}
sportData::sportData()
{
int iceTime = 0;
      int goals = 0;
      int points = 0;
      int penalties = 0;
      int assists = 0;
      string playerName = 0;
}
 sportData::sportData(int iT, int g, int p, int pen, int a, string n)
{
iceTime = iT;
goals = g;
points = p;
penalties = pen;
assists = a;
playerName = n;
       
} 

void sportData::getStats()//gets data
{
int test = 1;
cout << endl;
cout << "Enter Player Name: " ;
cin.ignore();
getline(cin, playerName);
while ((test == 1) || (iceTime <= -1))//error code
{
cout << "\nEnter Player's Time On Ice: ";
cin >> iceTime;
test = errorCode(iceTime);
}
while ((test == 1) || (goals <= -1))//error code
{
cout << "\nEnter Player's Goals: ";
cin >> goals;
test = errorCode(goals);
}
while ((test == 1) || (points <= -1))//error code
{
cout << "\nEnter Player's Points: ";
cin >> points;
test = errorCode(points);
}
while ((test == 1) || (penalties <= -1))//error code
{
cout << "\nEnter Player's Penalties: ";
cin >> penalties;
test = errorCode(penalties);
}
while ((test == 1) || (assists <= -1))//error code
{
cout << "\nEnter Player's Assists: ";
cin >> assists;
test = errorCode(assists);
}

cout << endl;

}//end func


void sportData::writeStats()//calculates average
{
fstream fs;
fs.open("playerStats.txt", ios::out | ios::app);
fs << playerName << " " << iceTime << " " << goals << " " << points << " " << penalties << " " << assists << endl; 
fs.close();
}//end func


void sportData::displayStats()//displays stock data
{
 fstream fs;
fs.open("playerStats.txt", ios::in);    
while (fs >> playerName >> iceTime >> goals >> points >> penalties >> assists)
{
cout << playerName << " " << iceTime << " " << goals << " " << points << " " << penalties << " " << assists << endl;
}//end while
fs.close();
}//end func


void sportData::execute(sportData players[])//if this assignment was a stir fry, this would be the pot with all the ingrediants in it.
{  
     int test = 1;
     while((test == 1) || (howMany > 100) || (howMany <= 0))
     {
   cout << "How Many Players Would You Like To Add?: ";
     cin >> howMany;
     test = errorCode(howMany);
     }//end while
     for (int i = 0; i < howMany; i++)
    {
     players[i].getStats();  
    }//end for
    system("pause");
    system("cls");    
     for (int i = 0; i < howMany; i++)
    {
     players[i].writeStats(); 
    }//end for
     for (int i = 0; i < howMany; i++)
    {
     players[i].displayStats();
    }//end for
    }//end func
    
    int sportData::errorCode(double testDoubleVariable)//for error coding doubles
{
char errorCh= ' ';
 if (cin.fail())
 {
 cin.clear();         
 cin >> errorCh;
 //if bad
 return 1; //1 is bad value need loopback     
}    //end if
else
{
    return 0;//good value
}//end else
}//end func

Any answers are appreciated! My class ends tomorrow so I am kind of panicking at this point.

thanks,

-Bryce
Last edited on
> I am sorry if my code is ugly
Don't.
Go and fix it (by instance, you could indent it)

http://www.cplusplus.com/forum/general/112111/
$ gdb a.out
(gdb) run
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct null not valid

Program received signal SIGABRT, Aborted.
(gdb) backtrace
...
#8  0x00007ffff7b923e6 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) () from /usr/lib/libstdc++.so.6
#9  0x000000000040148b in sportData::sportData (this=0x7fffffffd170) at foo.cpp:90
#10 0x00000000004012a0 in main () at foo.cpp:47
(i put everything in just one file, so don't pay attention to the line numbers)

Main is trying to create an array sportData players[100];//array of objects and that calls the constructor of 'sportData'
1
2
3
4
5
6
7
8
9
sportData::sportData()
{
	int iceTime = 0;
	int goals = 0;
	int points = 0;
	int penalties = 0;
	int assists = 0;
	string playerName = 0; //foo.cpp:90
}
http://www.cplusplus.com/reference/string/string/string/ it's invoking the 'from c-string' constructor, with NULL as parameter, hence the crash.

If you want an empty string you may do string playerName = ""; or simply string playerName


However, there is another problem in that code. You are simply defining local variables that would die when the constructor ends. The warnings may give you a clue about that
foo.cpp: In constructor ‘sportData::sportData()’:
foo.cpp:85:6: warning: unused variable ‘iceTime’ [-Wunused-variable]
foo.cpp:86:6: warning: unused variable ‘goals’ [-Wunused-variable]
foo.cpp:87:6: warning: unused variable ‘points’ [-Wunused-variable]
foo.cpp:88:6: warning: unused variable ‘penalties’ [-Wunused-variable]
foo.cpp:89:6: warning: unused variable ‘assists’ [-Wunused-variable]


To construct your members, use an initialization list


By the way, you shouldn't include cpp files. That would give you `multiple definition' errors.
Instead add them to your project. http://www.cplusplus.com/forum/general/113904/
Last edited on
Thank you, will try suggestions and indent my code :) I will post an update afterwards.

EDIT: Works like a charm! Great advice, thank you for putting up with my inexperience, I really appreciate your help.

I will post source code for anyone experiencing the same problem.

main:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

#include <iostream>
#include "sportData.h"
#include <iomanip>
#include <cmath>          
using namespace std;
    

int main()
{
    const int SIZE = 100;
    sportData list[SIZE];//array of objects
    char runAgain = ' ';
do
{
      
      sportData sportData;
      sportData.execute(list);//call member method
                 
      cout << "Return to menu?[Y|N]: ";
      cin >> runAgain;
      cin.ignore();
      runAgain = toupper(runAgain);
      system("pause");
      system("cls");    
}
while (runAgain == 'Y'); //end of do while
	
return 0;
}//end of main
/*
sample output

*/


header:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef sportData_H
#define sportData_H
#include <iostream>
#include <string>
#include <cstring>

using namespace std;



class sportData//class
{
      int iceTime;
      int goals;
      int points;
      int penalties;
      int assists;
      string playerName;
      
      
              
      public:
		 
      ~sportData();//public member methods
      sportData();    
      void getStats();
      void writeStats();
      void displayStats();
      void execute(sportData list[]);
      int errorCode(double testDoubleVariable);
};
#endif

methods and resources:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "sportData.h"
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
 
using namespace std;

      int howMany = 0;
     

sportData::~sportData()
{
}
sportData::sportData() : iceTime(0), goals(0), points(0), penalties(0), assists(0), playerName("")
{	
}
 

void sportData::getStats()//gets data
{
     int test = 1;
while (playerName == "")
{
     cout << endl;
     cout << "Enter Player Name: " ;
     cin.ignore();
     getline(cin, playerName);
}
while ((test == 1) || (iceTime < 0))//error code
{
      cout << "\nEnter Player's Time On Ice (in min): ";
      cin >> iceTime;
      test = errorCode(iceTime);
}
test = 1;
while ((test == 1) || (goals < 0))//error code
{
      cout << "\nEnter Player's Goals: ";
      cin >> goals;
      test = errorCode(goals);
}
test = 1;
while ((test == 1) || (points < 0))//error code
{
      cout << "\nEnter Player's Points: ";
      cin >> points;
      test = errorCode(points);
}
test = 1;
while ((test == 1) || (penalties < 0))//error code
{
      cout << "\nEnter Player's Penalties: ";
      cin >> penalties;
      test = errorCode(penalties);
}
test = 1;
while ((test == 1) || (assists < 0))//error code
{
      cout << "\nEnter Player's Assists: ";
      cin >> assists;
      test = errorCode(assists);
}

      cout << endl;

}//end func


void sportData::writeStats()
{
     fstream fs;
     fs.open("playerStats.txt", ios::out | ios::app);
     fs << playerName << " " << iceTime << " " << goals << " " << points << " " << penalties << " " << assists << endl; 
     fs.close();
}//end func


void sportData::displayStats()//displays stock data
{
     fstream fs;
     fs.open("playerStats.txt", ios::in);    
while (fs >> playerName >> iceTime >> goals >> points >> penalties >> assists)
{
      cout << "Name: " << playerName << "\nTime On Ice: " << iceTime << "\nGoals: " << goals << "\nPoints: " << points << "\nPenalties: " << penalties << "\nAssists: " << assists << endl;
      cout << "-----------------------------------------------------" << endl;
}//end while
       fs.close();
}//end func


void sportData::execute(sportData list[])//calls and executes member functions
{  
     int choice = 0;
     int test = 1;
while ((test == 1) || (choice > 2) || (choice < 1))
     {
     cout << "Enter 1 to write player stats or 2 to view player stats: ";
     cin >> choice;
     test = errorCode(choice);
     }
switch (choice)
     {
            case 1:
                 
     test = 1;
while((test == 1) || (howMany > 100) || (howMany < 0))
{
            cout << "\nHow Many Players Would You Like To Add?: ";
            cin >> howMany;
            test = errorCode(howMany);
}//end while
for (int i = 0; i < howMany; i++)
{
    list[i].getStats();  
}//end for
       system("pause");
       system("cls");    
       
for (int i = 0; i < howMany; i++)
{
    list[i].writeStats(); 
}//end for
                          break;
            case 2:
                 cout << "-----------------------------------------------------" << endl;
for (int i = 0; i < howMany - 1; i++)
{
    list[i].displayStats();
}//end for
                          break;
}//end switch
}//end func
    
int sportData::errorCode(double testDoubleVariable)//for error coding doubles
{
    char errorCh= ' ';
    if (cin.fail())
 {
    cin.clear();         
    cin >> errorCh;
 //if bad
      return 1; //1 is bad value need loopback     
}    //end if
else
{
      return 0;//good value
}//end else
}//end func
Last edited on
Topic archived. No new replies allowed.