News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Runtime Error when compiling basic I/O code

Started by HadMatter, April 08, 2012, 09:46:22 PM

Previous topic - Next topic

HadMatter

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:
#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:

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!

oBFusCATed

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!
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

jarod42

Oper += ThisLetter;

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