[Access Violation]: Debug Help

This is a discussion on [Access Violation]: Debug Help within the C++ Programming forums, part of the General Programming Boards category; >> what's so wrong about using cstrings in me' code..?!?!? Nothing. It's your choice. IMO many C++ programmers (especially beginners) ...

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> what's so wrong about using cstrings in me' code..?!?!?

    Nothing. It's your choice. IMO many C++ programmers (especially beginners) would benefit from learning and using C++ tools, and many just use C versions because their class/instructor/book uses them and they don't know any better. I can see wanting to stay consistent when going through Petzold, but the algorithm above would be simpler, easier and safer (IMO) with C++ tools.

  2. #17
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,805
    One thing I see is this Brain. You need to add + 1 on your new's because strlen does not count the null terminator. E.G
    Code:
    #include <iostream>
    #include <cstring>
    
    int main()
    {
        unsigned int getLen = std::strlen("Hello\0");
        
        std::cout<<getLen<<std::endl;
        
        std::cin.get();
        
        return 0;
    }
    This is 5 not 6.
    Woop?

  3. #18
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    fixed...


    good catch...


    (so many little nuances to remember..!!! )
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #19
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    There's also no need to add the null terminator to the string literals. It is there automatically.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary not built with debug info - why?
    By ulillillia in forum C Programming
    Replies: 15
    Last Post: 12-11-2008, 12:37 AM
  2. makefiles - debug & release?
    By cpjust in forum C Programming
    Replies: 6
    Last Post: 10-26-2007, 04:00 PM
  3. Debug --> Exceptions in Visual Studio 2005
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-10-2007, 02:12 AM
  4. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 11:08 AM
  5. Ask about Debug Assert Failed
    By ooosawaddee3 in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2002, 11:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21