String to char*

Discussion in 'C++' started by Maciej, Jul 4, 2005.

  1. Maciej

    Maciej Guest

    Hallo,

    Can I convert type String to char* ??
    I need to use fstream in my application together with openfiledialog.

    Thanks,

    Maciek
     
    Maciej, Jul 4, 2005
    #1
    1. Advertising

  2. Maciej

    Leon Mergen Guest

    On Mon, 2005-07-04 at 14:09 +0200, Maciej wrote:
    > Can I convert type String to char* ??
    > I need to use fstream in my application together with openfiledialog.


    std::string foo = "bar";
    char * wombat = strdup ( foo.c_str() );

    Regards,

    Leon Mergen
     
    Leon Mergen, Jul 4, 2005
    #2
    1. Advertising

  3. Maciej

    Maciej Guest

    I mean the String Class not a std::string.

    Regards,

    Maciek

    U¿ytkownik "Leon Mergen" <> napisa³ w wiadomo¶ci
    news:...
    > On Mon, 2005-07-04 at 14:09 +0200, Maciej wrote:
    > > Can I convert type String to char* ??
    > > I need to use fstream in my application together with openfiledialog.

    >
    > std::string foo = "bar";
    > char * wombat = strdup ( foo.c_str() );
    >
    > Regards,
    >
    > Leon Mergen
    >
     
    Maciej, Jul 4, 2005
    #3
  4. Maciej

    Alan Johnson Guest

    Maciej wrote:
    > U¿ytkownik "Leon Mergen" <> napisa³ w wiadomo¶ci
    > news:...
    >
    >>On Mon, 2005-07-04 at 14:09 +0200, Maciej wrote:
    >>
    >>>Can I convert type String to char* ??
    >>>I need to use fstream in my application together with openfiledialog.

    >>
    >>std::string foo = "bar";
    >>char * wombat = strdup ( foo.c_str() );
    >>
    >>Regards,
    >>
    >>Leon Mergen
    >>

    >
    > I mean the String Class not a std::string.
    >
    > Regards,
    >
    > Maciek


    (Reordered to undo top-posting.)

    std::string and std::wstring are the only string classes provided by
    standard C++.

    -Alan
     
    Alan Johnson, Jul 4, 2005
    #4
  5. Maciej wrote:
    >
    > I mean the String Class not a std::string.


    1) Please don't top post.
    Put your reply beneath the text you are replying to

    2) the String Class in C++ *is* std::string
    There is no other String Class in standard C++.
    If you use some other class, please ask the creators of that
    class how to do it, or post to a newsgroup where that class is topical.


    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Jul 4, 2005
    #5
  6. "Maciej" <> schrieb:

    > I mean the String Class not a std::string.


    I've seen about 20 different String classes in my live. How about
    looking into the list of methods of this class?

    T.M.
     
    Torsten Mueller, Jul 4, 2005
    #6
  7. Maciej

    Maciej Guest

    1) my mistake, sorry

    I want to write a simple application using openfiledialog, and fstream.
    I am not able to convert openfiledialog->filename to use it in open()
    function of fstream. Filename is .net framework library String Class (MS
    Visual Studio .Net).

    Regards,

    Maciek

    Uzytkownik "Karl Heinz Buchegger" <> napisal w wiadomosci
    news:...
    > Maciej wrote:
    > >
    > > I mean the String Class not a std::string.

    >
    > 1) Please don't top post.
    > Put your reply beneath the text you are replying to
    >
    > 2) the String Class in C++ *is* std::string
    > There is no other String Class in standard C++.
    > If you use some other class, please ask the creators of that
    > class how to do it, or post to a newsgroup where that class is topical.
    >
    >
    > --
    > Karl Heinz Buchegger
    >
     
    Maciej, Jul 4, 2005
    #7
  8. Maciej

    Maciej Guest

    I have tried msdn.com, but it is very hard for me to find a relevant
    function.

    Maciek

    Uzytkownik "Rolf Magnus" <> napisal w wiadomosci
    news:dabamj$lqb$01$-online.com...
    > Please don't top-post. Fixed.
    >
    > Maciej wrote:
    >
    > >> > Can I convert type String to char* ??
    > >> > I need to use fstream in my application together with openfiledialog.
    > >>
    > >> std::string foo = "bar";
    > >> char * wombat = strdup ( foo.c_str() );

    > >
    > > I mean the String Class not a std::string.

    >
    > std::string is C++'s string class. There is no class called "String" in
    > standard C++. If you're using some other library that provides such a
    > class, you better look into that library's documentation or ask in a
    > newsgroup where that library is topical.
    >
     
    Maciej, Jul 4, 2005
    #8
  9. Maciej

    Rolf Magnus Guest

    Please don't top-post. Fixed.

    Maciej wrote:

    >> > Can I convert type String to char* ??
    >> > I need to use fstream in my application together with openfiledialog.

    >>
    >> std::string foo = "bar";
    >> char * wombat = strdup ( foo.c_str() );

    >
    > I mean the String Class not a std::string.


    std::string is C++'s string class. There is no class called "String" in
    standard C++. If you're using some other library that provides such a
    class, you better look into that library's documentation or ask in a
    newsgroup where that library is topical.
     
    Rolf Magnus, Jul 4, 2005
    #9
  10. Maciej

    benben Guest

    > I want to write a simple application using openfiledialog, and fstream.
    > I am not able to convert openfiledialog->filename to use it in open()
    > function of fstream. Filename is .net framework library String Class (MS
    > Visual Studio .Net).


    Try System::String::ToCharArray()

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
    frlrfsystemstringclasstochararraytopic.asp
     
    benben, Jul 4, 2005
    #10
  11. Maciej

    Maciej Guest

    Form1.h(79): error C2664: 'void
    std::basic_ifstream<_Elem,_Traits>::eek:pen(const char
    *,std::_Iosb<_Dummy>::eek:penmode,int)' : cannot convert parameter 1 from
    '__wchar_t __gc[]' to 'const char *'
    with
    [
    _Elem=char,
    _Traits=std::char_traits<char>,
    _Dummy=int
    ]

    Not working. Unfortunately.

    U¿ytkownik "benben" <> napisa³ w wiadomo¶ci
    news:42c93442$0$20023$...
    > > I want to write a simple application using openfiledialog, and fstream.
    > > I am not able to convert openfiledialog->filename to use it in open()
    > > function of fstream. Filename is .net framework library String Class (MS
    > > Visual Studio .Net).

    >
    > Try System::String::ToCharArray()
    >
    >

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
    > frlrfsystemstringclasstochararraytopic.asp
    >
    >
     
    Maciej, Jul 4, 2005
    #11
  12. Maciej

    benben Guest

    Well, String.ToCharArray returns a System.Char[], which is almost equivalent
    to the build in wchar_t, which is twice as long as char (remember .Net uses
    unicode all the way).

    But then, why you want to use std::ifstream if you can just use the .Net
    class library? I don't think the .Net thinggy and the standard library mix
    well.

    ben
     
    benben, Jul 4, 2005
    #12
  13. Maciej

    Peter Julian Guest

    "Maciej" <> wrote in message
    news:daba0g$gha$...
    > I mean the String Class not a std::string.
    >
    > Regards,
    >


    Then why ask here? String is proprietary. std::string and std::wstring are
    part of the standard.
     
    Peter Julian, Jul 4, 2005
    #13
  14. Maciej

    Shaun Guest

    what you want can be found here:

    http://blogs.msdn.com/slippman/archive/2004/06/02/147090.aspx

    note that the concept still applies even if you aren't using Whidbey.

    And for future reference, you'll want to post questions like this to
    the relevant microsoft.public.* newsgroup. Folks here tend to
    appreciate sticking to the c++ standard libraries.
     
    Shaun, Jul 6, 2005
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wwj
    Replies:
    7
    Views:
    581
  2. wwj
    Replies:
    24
    Views:
    2,548
    Mike Wahler
    Nov 7, 2003
  3. Ben Pfaff
    Replies:
    5
    Views:
    490
    Tristan Miller
    Jan 17, 2004
  4. Steffen Fiksdal

    void*, char*, unsigned char*, signed char*

    Steffen Fiksdal, May 8, 2005, in forum: C Programming
    Replies:
    1
    Views:
    607
    Jack Klein
    May 9, 2005
  5. lovecreatesbeauty
    Replies:
    1
    Views:
    1,099
    Ian Collins
    May 9, 2006
Loading...

Share This Page