CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2001
    Posts
    11

    Str() vb equivilant in C++?

    Hello-
    Just a quick question, is there an equivilant to the VB function str() which takes an integer, long, or float, and converts it into a string? Or, will I have to write my own in order to accomplish this task. Many thanks.
    Brendan


  2. #2
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    2,147

    Re: Str() vb equivilant in C++?

    Using CString...

    CString MyString;

    MyString.Format("%d", MyInteger);

    MyString.Format("%ld", MyLong);

    MyString.Format("%f", MyFloat);



    or Using character based array...

    char MyBuffer[200];

    wsprintf(MyBuffer, "%d", MyInteger);

    wsprintf(MyBuffer, "%f", MyFloat);

    // Etc..



    Hope this helps,

    - Nigel



  3. #3
    Join Date
    Jul 2001
    Posts
    11

    Re: Str() vb equivilant in C++?

    Thank you very much for your reply!
    Brendan


  4. #4
    Join Date
    Nov 2000
    Posts
    13

    Re: Str() vb equivilant in C++?

    Brendan, if you include stdlib.h you can use
    itoa - integer to asci
    atoi - asci to integer

    There are also equivs to long and float.



    char buf[20];
    int num = 100;

    itoa(num,buf, 10);

    cout<<"string: "<<buf;



  5. #5
    Join Date
    Jul 2001
    Posts
    11

    Re: Str() vb equivilant in C++?

    Thank you, both are good ways for what I need to do.
    Brendan


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured