User forums > General (but related to Code::Blocks)
Runtime Error when compiling basic I/O code
(1/1)
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:
--- 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;
}
--- End code ---
If I comment out the line:
--- Code: ---Oper.at(i) = ThisLetter;
--- End code ---
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!
jarod42:
Oper += ThisLetter;
string::at is an accessor and can't append new char.
Navigation
[0] Message Index
Go to full version