Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: HadMatter on April 08, 2012, 09:46:22 pm

Title: Runtime Error when compiling basic I/O code
Post by: HadMatter on April 08, 2012, 09:46:22 pm
Hey guys, So I'm working on a project to create an assembler. I am kind of reintroducing myself to C++, and finally after getting my code to compile, I am getting a runtime error. I am using Code::Blocks with the GNU GCC compiler on a windows 7 machine

The Error: "This application has requested the Runtime to terminate it in an unusual way."

From what I can gather, this is due to the terminate() function being called possibly due to an unhandled exception

My Code:
Code
#include <iostream>
#include <fstream>
#include <string.h>

using namespace std;

int main()
{
    string Oper;
    string Src;
    string Dst;
    int OpCode;
    char ThisLetter;
    char a = ' ';

    cout<<"here";

    ifstream file;
    file.open("Assy.txt");
    if (!file.good())
    {
        cout << "There was an error opening the file." << endl;
        return 0;
    }
    int i = 0;

    while(ThisLetter != a)
    {
        ThisLetter = file.get();
        cout<< ThisLetter;
        Oper.at(i) = ThisLetter;
        i++;
    }
    cout << Oper;

    file.close();

        return 1;
}

If I comment out the line:

Code
Oper.at(i) = ThisLetter;

It works, and the loop exits. The cout statements are purely for debug purposes. Any tips on where to look for a solution to this problem? I hope this is enough information. If you guys need anything else, let me know. Thanks!
Title: Re: Runtime Error when compiling basic I/O code
Post by: oBFusCATed on April 08, 2012, 10:11:17 pm
Yes, use the debugger and read a book about the api you're using!

p.s. also read the rules, because you're violating them!
Title: Re: Runtime Error when compiling basic I/O code
Post by: jarod42 on April 10, 2012, 10:06:35 am
Oper += ThisLetter;

string::at is an accessor and can't append new char.