Issue with User Input

When I call the following section of code, I get to the section to enter an integer for enter number of grades to drop and my program crashes.

[code]void Course::enterGCInfo(int num)
GradeCat tempGC;
string tempStr = "";
cout << "Enter Grade Category Name: ";
cin >> tempStr;
double tempDbl = 0.0;
cout << "Enter Grade Percentage: ";
cin >> tempDbl;
int tempInt = 0;
cout << "Enter Number of Grades To Drop: ";
cin >> tempInt;

This is the error message:
[code]Unhandled exception at 0x004149eb in Grade Tracker.exe: 0xC0000005: Access violation reading location 0x3343f1c8.[/code]

I'm using Visual Studio 2010 Express - Start Debugging. When it reaches this error it takes me to following code in file xstring

[code] bool _Grow(size_type _Newsize,
bool _Trim = false)
{ // ensure buffer is big enough, trim to size if _Trim is true
if (max_size() < _Newsize)
_Xlen(); // result too long
if (this->_Myres < _Newsize)
_Copy(_Newsize, this->_Mysize); // reallocate to grow
else if (_Trim && _Newsize < this->_BUF_SIZE)
_Tidy(true, // copy and deallocate if trimming to small string
_Newsize < this->_Mysize ? _Newsize : this->_Mysize);
else if (_Newsize == 0)
_Eos(0); // new size is zero, just null terminate
return (0 < _Newsize); // return true only if more work to do

The cursor stops next to this line:
[code]if (this->_Myres < _Newsize)[/code]

The function calls dealing with that Integer input

[code]void GradeCat::setNumToDrop(int num)
numToDrop = num;

[code]void Course::setGradeCat(int num,GradeCat tempGC)
GCs[num] = tempGC;

GCs is an array of GradeCat objects

[code]void Course::refresh()


  • umm, you'll have to put that into so easier language to me to understand.

    Anyway, I figured out my problem, I knew it would be something stupid. I was not sending a proper value to the function, so that improper value was being used to insert an object into an array. DOH!
  • why all = faknob? i want know! :(
  • i see how they = st00pid but they all die... :(

    man listen i want to start creating my own games in C++ using directx9. but i'm right at the start! i'm barely at chapter 4 from Thinking in C++. and i have some questions about what i learned. so take this as an example

    void (*funcptr)();
    //so this is a pointer to a function which takes no arguments and returns void

    void* funcptr2();
    //a function which returns a pointer to void

    void* (*(*fp1)(int))[10];
    //fp1 is a pointer to a function which takes an int an returns a pointer to an array of 10 pointers to void

    float (*(*fp2)(int,int,float))(int);
    //fp2 is a pointer to a function which takes 3 arguments and returns a pointer to a function which takes an int and returns float

    i can read most of these expressions using the middle-right-left-right-etc method described in the book. but i'm not sure i can use this stuff - it seems too complicated. so if i take up game programming would i bump often into such things?

    PS i now mother not home but she come late ok?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!