Thread: Garbbage in the variable

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by Elysia View Post
    Then why are you using C?
    Um! It looks like I need more help than I thought.
    Please point me in the right direction so that I can learn the
    correct way of C++ programming for a GUI or Windows... Will appreciate it - a lot!

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    He probably means you should use the std::string class to do whatever you are doing. It makes things easier.
    Code:
    std::string bucket("hello world");
    bucket.insert(6, "sick, sad ");
    std::cout <<'\'' << bucket << '\'' << std::endl;
    See? There is a starting tutorial over here: Cprogramming.com - C++ Standard Library - String Class. That said, it wasn't really wrong of you to learn character arrays first. People have different approaches to learning C++. But std::string is basically the preferred type.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by whiteflags View Post
    There is a starting tutorial over here: Cprogramming.com - C++ Standard Library - String Class.
    To delete an entire string, you could use
    str.erase(0, str.length());
    I like this part... wiping a string...
    Code:
    using namespace std::string cup;
    .
    .
    .
    cup.erase( 0, cup.length() );
    .
    .
    .
    Is that correct?
    With std::string may help avoid getting garbage into the cup variable... amazing! Awhile ago I could not grasp
    the concept behind std::xxxxxxx ... I take it that I am ready now... Do you have any links to sample code of
    simple programs designed for windows?

    Thank you Whiteflags, and Elysia... looking forward not being a C+ programmer.... hehehe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Realloc problem, environment variables Linux C
    By yodakohl in forum C Programming
    Replies: 4
    Last Post: 01-05-2011, 07:04 PM
  2. Pointers
    By MrMatt027 in forum C++ Programming
    Replies: 14
    Last Post: 12-10-2010, 04:32 PM
  3. Question about printing a variable???
    By Hoser83 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2006, 01:57 PM
  4. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  5. Replies: 2
    Last Post: 04-12-2004, 01:37 AM