What actually happens when we use strings

This is a discussion on What actually happens when we use strings within the C++ Programming forums, part of the General Programming Boards category; Code: String TTextFile::Load() const { String Text; ifstream File(itsPath.c_str()); if (File.is_open()) { while (File.good()) { Text += File.get()); } File.close(); ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    160

    What actually happens when we use strings

    Code:
    String TTextFile::Load() const
    {
      String Text;
    
      ifstream File(itsPath.c_str());
    
      if (File.is_open())
      {
        while (File.good())
        {
          Text += File.get());
        }
    
        File.close();
      }
    
      return Text;
    }
    Code:
    char * TTextFile::Load() const
    {
      char *Text = "";
    
      ifstream File(itsPath);
    
      if (File.is_open())
      {
        while (File.good())
        {
          Length = strlen(Text);
    
          char *Temp = new char[Length + 1]
          strcpy(Temp, Text);
    
          delete Text;
          Text = new char[Length + 2];
          
          strcpy(Text, Temp);
          Text[Length] = File.get();
          Text[Length + 1] = '\0';
        }
    
        File.close();
      }
    
      return Buffer;
    }
    I just wanted to show you all what actually happens when we use strings (though the use of strings furthermore will increase the function calls), simply because alot of people think the one above is faster then the one below and that is just wrong.
    Last edited by Zahl; 04-26-2003 at 04:06 PM.
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 07:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 03:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 12:23 PM

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