Author Topic: Why does it gives me error?  (Read 4421 times)

0 Members and 1 Guest are viewing this topic.

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Why does it gives me error?
« on: September 14, 2011, 12:17:52 am »
So, I was trying to make base converter as my first C++ file, but it gave me
Code: [Select]
Microsoft C++ exception: std::out_of_range at memory location 0x003ffd20..
Unhandled exception at 0x778fb9bc in convert.exe: Microsoft C++ exception: std::out_of_range at memory location 0x003ffd20..
convert.exe has triggered a breakpoint
while running the code.
Why?
code at link.
http://pastebin.com/Qw1235tD
Sig wipe!

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Why does it gives me error?
« Reply #1 on: September 14, 2011, 02:57:33 am »
You need to use a Debugger. Not sure if there's a Debugger for Microsoft C++. So I recommend using C++ instead of Visual C++.

Install Code:Blocks with MingW + GDB Debugger and you can debug the program ;)

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: Why does it gives me error?
« Reply #2 on: September 14, 2011, 03:02:03 am »
That looks to be a problem with the compilation process. Is it installed properly?

Also, MSVC++ has a really good debugger that's easier to use compared to GDB.
« Last Edit: September 14, 2011, 03:03:11 am by Netham45 »
Omnimaga Admin

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Why does it gives me error?
« Reply #3 on: September 14, 2011, 07:03:49 am »
so my code is correct, right?
Sig wipe!

Ashbad

  • Guest
Re: Why does it gives me error?
« Reply #4 on: September 14, 2011, 08:02:11 am »
so my code is correct, right?

I don't see anything wrong with the code, it does nothing out of the ordinary.  I'm with Netham, it's something to do with the compilation process probably.  The MSVC++ is rather easy to mess up with at primary installation, so perhaps reinstall the compiler?

Ephan: I doubt there is no debugger for VC++.  MinGW is a good suggestion, but it is harder to setup for newbies and even harder to work with (makefiles, complex command line invocations, etc.) so perhaps let's see if we can get VC++ working for you first before you convert.

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Why does it gives me error?
« Reply #5 on: September 14, 2011, 08:11:45 am »
I tried to install gnc gcc or something, but it's kinda complicated so...
can anyone tell me a easy step by step how to do it?
Sig wipe!

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Why does it gives me error?
« Reply #6 on: September 14, 2011, 09:23:27 am »
First let's try debugging your Visual C++ program. One thing I notice is that you're indexing all of your substrings starting at 1 instead of 0. Also, you're trying to use the ^ operator as exponentiation, when it is really bitwise XOR. Try using math.pow() instead. On line 35, you're also indexing your string with temp instead of temp3.

Edit: I bet std::out_of_range is caused by a bad substr call. Remember, indices only go from 0 to length-1. Index at length and it's out of range.
« Last Edit: September 14, 2011, 09:26:27 am by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Why does it gives me error?
« Reply #7 on: September 14, 2011, 10:33:21 am »
O.o I just relised. XP
Thanks.
I was *porting* my ti84 prgm to C++ XP
maybe I made a mistake then.
Sig wipe!