mem leak using string...

This is a discussion on mem leak using string... within the C++ Programming forums, part of the General Programming Boards category; could you help me out fixing this? this is all my code so far: Code: #include <iostream> #include <fstream> #include ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    8

    mem leak using string...

    could you help me out fixing this? this is all my code so far:

    Code:
    #include
    <iostream>
    
    #include
    <fstream>
    
    #include
    <string>
    
    class Cipher
    {
    private:
         
    const string DEST_FOLDER;
    };
    
    Cipher::Cipher():DEST_FOLDER("d:\\Fun\\Test\\")
    {
    
    }
    
    int main()
    
    {
    
        Cipher c;
    
        
    //c.encrypt("input2.txt", "result.txt", "key2.txt");
    return 0;
    
    }
    
    
    
    there is a memory leak ... I need help. Thanks

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,546
    There is no memory leak in this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    8
    Quote Originally Posted by Elysia View Post
    There is no memory leak in this.
    when using _CrtDumpMemoryLeaks();
    just before the return 0;
    in visual studio i get this:
    Code:
    Detected memory leaks!
    
    Dumping objects ->
    
    {124} normal block at 0x005F44C8, 8 bytes long.
    
     Data: <P #     > 50 FC 23 00 00 00 00 00 
    
    Object dump complete.
    


    (of course the address and the data change every time i run the program).

    It seems to me weird too there is a leak. Dunno what to do =/ Help would be appreciated Thanks~

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,546
    That is because your cipher has not gone out of scope yet. Introduce a local scope and you will see.

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    8
    Oh WOW... I'm so stupid.. Thank you so much!! ... I could on it few more hours without seeing it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. string declaration and memory leak?
    By ignazioc in forum C Programming
    Replies: 7
    Last Post: 01-08-2012, 04:17 AM
  2. is a leak... or is it not?
    By nantonop in forum Tech Board
    Replies: 15
    Last Post: 04-26-2007, 09:08 AM
  3. Is this a memory leak?
    By jasonhv in forum C++ Programming
    Replies: 5
    Last Post: 10-20-2005, 08:37 PM
  4. c style string memory leak question
    By curlious in forum C++ Programming
    Replies: 7
    Last Post: 09-14-2003, 06:31 AM
  5. Doom III leak
    By napkin111 in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 01-05-2003, 05:25 PM

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