how do you declare a string?

This is a discussion on how do you declare a string? within the C++ Programming forums, part of the General Programming Boards category; topic...

  1. #1
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    how do you declare a string?

    topic

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    #include <string>
    
    int main()
    {
      std::string s;
    }
    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    Only:

    string a,b;

    won't do ???
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    nope. not unless you have beforehand either of these directives.

    using namespace std;

    using std::string;
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    For which compiler???

    I am using Borland 5.02 and its not giving any errors.

    Besides where I can get the newest STL files ??? (only files not the whole compiler
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    borland ships with STLPort. you can get it here
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    Thank you very much. I am a newcomer to C++. I have just leaned the basics.

    Now I want to start Graphics Programming but I don't know Which will be better for me to buy; MSVC++ or Borland C++ Builder ???
    Last edited by Moni; 03-28-2003 at 01:21 PM.
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    the term string can be used to refer to several different things. The responses so far have to do with declaring objects of the STL string class, which a very nice type of string. But your message doesn't specifically ask about the STL string class. Therefore you should know that there are other things that are called strings, too. In particular there are other string classes besides the STL string class and then, of course, there is the granddaddy of all strings, the null terminated char array. As already pointed out with the STL string class, each of the types of string has several ways to be declared. For null terminated char array both array and pointer syntax can be used.

    In addition to the confusion regarding declaration of a string, the variety of ways to intialize, assign, and otherwize deal with strings frequently leads to confusion. Being clear about what type of string you are using is the first step to being able to use it.

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    If you are a newcommer to programming in general, or if you want to do graphics in c++; you need to evaluate if you are ready.

  10. #10
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    Originally posted by alpha
    If you are a newcommer to programming in general, or if you want to do graphics in c++; you need to evaluate if you are ready.
    Hello! Alpha!
    I am not sure what you are talking about. Can you make it clear to me ???
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  11. #11
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    Originally posted by Moni
    For which compiler???

    I am using Borland 5.02 and its not giving any errors.

    Besides where I can get the newest STL files ??? (only files not the whole compiler
    I have downloaded it but :

    http://www.stlport.com/dcforum/DCForumID7/1502.html

    What can I do ???
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  12. #12
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    I am in trouble ! I really need a very good help !
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  13. #13
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by Moni
    Hello! Alpha!
    I am not sure what you are talking about. Can you make it clear to me ???
    You should learn more about programming, more concepts, and make sure you understand the concepts before even thinking about graphics, win32api, game development, etc. You may and probably will find it difficult to do these without knowing programming more in depth.

    So, if you are new to programming, you will need to evaluate whether or not you are ready to start graphics. If you are not new, and know more in depth programming concepts through C or something, then it is up to you.

  14. #14
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    Originally posted by alpha
    You should learn more about programming, more concepts, and make sure you understand the concepts before even thinking about graphics, win32api, game development, etc. You may and probably will find it difficult to do these without knowing programming more in depth.

    So, if you are new to programming, you will need to evaluate whether or not you are ready to start graphics. If you are not new, and know more in depth programming concepts through C or something, then it is up to you.
    Oh! Thanks for your suggesion. I am not a total newbie. I am familier with programming for 1.5 year. I already know C and have fundamental C++ and now I wanna learn Graphics programming in C++.

    But now I am in great trouble with STLPORT installing in my Borland 5.02 no documentation is helping!!!

  15. #15
    Registered User
    Join Date
    Mar 2003
    Posts
    73
    Originally posted by Moni

    But now I am in great trouble with STLPORT installing in my Borland 5.02 no documentation is helping!!!
    Is that for the free DOS compiler Borland offers? I gave up on that, using Dev C++ (for nothing professional mind you) and it has worked great for me so far. I also haven't had to deal with any errors yet. You might want to check that out.

    If not, I'm sure others here that use it could help you.

    Btw, strings declared with arrays are done like this: (someone mentioned it, but never showed how)

    Code:
    char string[11]; //creates a char array of 10 available spaces for text
    It's also one of the easiest ways to declare strings to understand, IMO.

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

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM

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