Find the answer to your Linux question:
Results 1 to 2 of 2
i am using execv("/bin/ls", s, NULL) Now s is a string... how do i convert it to Char * in C++ Also i have wstring...can anything b done for conversion ...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    15

    Convert string to Char*

    i am using execv("/bin/ls", s, NULL)

    Now s is a string... how do i convert it to Char * in C++
    Also i have wstring...can anything b done for conversion to Char *?

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    There is a method for strings called c_str(). It returns, as you might guess, a C string version of the string.

    As for wstrings, I don't know anything about them (I don't do much C++ programming), but I did find some documentation. I found this page very helpful:
    basic_string<charT, traits, Alloc>

    Basically, string and wstring are both typedefs for a special version of basic_string. As a result, I imagine that wstring also has a c_str() method, but it probably returns a wchar_t *, not a char *. You can probably find a way to use this, however.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

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