sorry I ask dumb questions...
I tried debugging, it sends me to the bracket under int main() and crtexe.h
I get this.. er.. thing when I run it:
[quote]Unhandled exception at 0x76e9b727 in stuff.exe: Microsoft C++ exception: std::out_of_range at memory location 0x003ef690..[/quote]
here's the code:
[cpp] void ParseFile(char* pFil)
{
std::fstream fil(pFil, std::fstream::in | std::fstream::out | std::fstream::trunc);
while(!fil.eof())
{
std::string sParse;
std::string line;
std::getline(fil, line);
sParse = line.substr(12, 64);
std::cout << sParse;
}
}
[/cpp]
Misallocated memory: you win!
teach me
I don't do much C++ so I can't point out the error by looking at your code. In your case, neither can the debugger. Something went wrong. It can be your memory, the way you wrote the code, the way the debugger is written, WINDOWS or other crap malfunctioning. Bottom line SOMETHING tried reading SOMETHING ELSE'S allocated memory. No you didn't really win.
[QUOTE=KD007;16807123]I don't do much C++ so I can't point out the error by looking at your code. In your case, neither can the debugger. Something went wrong. It can be your memory, the way you wrote the code, the way the debugger is written, WINDOWS or other crap malfunctioning. Bottom line SOMETHING tried reading SOMETHING ELSE'S allocated memory. No you didn't really win.[/QUOTE]
the fuck are you on about buddy.
Sorry I watched a soap opera.
Actually a std::out_of_range exception occurs when you give a nonexistent index to a container that does bounds checking, such as a std::string.
The problem is probably on line 9, where you're trying to get characters 12 through 64 of your string -- if the string is less than 12 characters long, you'll get that exception. (The second parameter is allowed to be past the end of the string, but the first parameter is not since you can't begin at a place that's past the end.)
It's probably line.substr(12, 64); that is causing it.
Check if the string is long enough before doing that.
Finally, you should learn more about the debugger. You can set a breakpoint right before calling ParseFile and step line-by-line through the code and see exactly what threw the exception.
if I do line.substr(12, line.length()); it throws the same thing
also, where can I find something to teach me about the debugger?
[QUOTE=raccoon12;16807627]if I do line.substr(12, line.length()); it throws the same thing[/QUOTE]
That's because, as said, the line doesn't have as much as 12 characters in it. The second argument is irrelevant.
[QUOTE=raccoon12;16807627]also, where can I find something to teach me about the debugger?[/QUOTE]
Just google it...
You need to do something like:
[code]
if(line.length >= 12)
sParse = line.substr(12,64);
[/code]
To check that line is long enough first. I don't know what you are trying to do, but you should be able to apply that to your goal.
Where is the file located? With different IDEs and compilers, the working directory can be different to your code directory. Try Putting your file in C:\ and making the file location string: C:\Raccoon.txt
Edit: That's wrong, sorry.
ja_cop was right, it is line.substr, but I don't know why
the file has "playername = tim" in it
Sorry, you need to Log In to post a reply to this thread.