DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: String data type

  1. #1
    Adam Guest

    String data type


    I know in Borland Builder 4 you can declare a string data type like so:

    string str1 = "Adam";

    In order to do this you need to declare the string.h file. THis makes working
    with string literals a ton easier. I tried this in Microsoft VC++ but it
    doesn't work. Is there anyway that I can get this to work in MVC++.

    Thanks a bunch in advance!!


  2. #2
    Stu Guest

    Re: String data type


    Adam,
    if you have created your apllication using AppWizard then all
    you have to do is us an object of class CString like this:

    CString string;
    string = "Hello";

    CString is really useful and has loads of useful member functions
    which I reccomend you read in MSDN. I haven't worked with apps
    that aren't created without AppWizard so you might have trouble
    with CString. It's an Foundation Class so you should be able to
    use it.

    Hope this helps
    Stu


    "Adam" <trepaa59@uwosh.edu> wrote:
    >
    >I know in Borland Builder 4 you can declare a string data type like so:
    >
    >string str1 = "Adam";
    >
    >In order to do this you need to declare the string.h file. THis makes working
    >with string literals a ton easier. I tried this in Microsoft VC++ but it
    >doesn't work. Is there anyway that I can get this to work in MVC++.
    >
    >Thanks a bunch in advance!!
    >



  3. #3
    Danny Kalev Guest

    Re: String data type

    <string.h> and <string> are two entirely different header files. the
    first contains the C str- family of functions, e.g., strcpy, strcmp etc.
    The second header contains definitions of the C++ string class (as well
    as its wide char equivalent, wstring). These classes are declared in
    namespace std. To make your code work, you need to add the following

    #include <string>
    using std::string;
    string str1 = "Adam";

    Danny Kalev

    "The ANSI/ISO C++ Professional Programmer's Handbook"
    http://www.amazon.com/exec/obidos/ASIN/0789720221

    Please reply to the newsgroup.


    Adam wrote:
    >
    > I know in Borland Builder 4 you can declare a string data type like so:
    >
    > string str1 = "Adam";
    >
    > In order to do this you need to declare the string.h file. THis makes working
    > with string literals a ton easier. I tried this in Microsoft VC++ but it
    > doesn't work. Is there anyway that I can get this to work in MVC++.
    >
    > Thanks a bunch in advance!!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center