Connecting Tech Pros Worldwide Help | Site Map

String to char*

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 05:50 AM
Maciej
Guest
 
Posts: n/a
Default String to char*

Hallo,

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

Thanks,

Maciek



  #2  
Old July 23rd, 2005, 05:50 AM
Leon Mergen
Guest
 
Posts: n/a
Default Re: String to char*

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

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

Regards,

Leon Mergen

  #3  
Old July 23rd, 2005, 05:50 AM
Maciej
Guest
 
Posts: n/a
Default Re: String to char*

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

Regards,

Maciek

Użytkownik "Leon Mergen" <lmergen@gmail.com> napisał w wiadomości
news:1120479782.7799.1.camel@localhost.localdomain ...[color=blue]
> On Mon, 2005-07-04 at 14:09 +0200, Maciej wrote:[color=green]
> > Can I convert type String to char* ??
> > I need to use fstream in my application together with openfiledialog.[/color]
>
> std::string foo = "bar";
> char * wombat = strdup ( foo.c_str() );
>
> Regards,
>
> Leon Mergen
>[/color]


  #4  
Old July 23rd, 2005, 05:50 AM
Karl Heinz Buchegger
Guest
 
Posts: n/a
Default Re: String to char*

Maciej wrote:[color=blue]
>
> I mean the String Class not a std::string.[/color]

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
kbuchegg@gascad.at
  #5  
Old July 23rd, 2005, 05:50 AM
Torsten Mueller
Guest
 
Posts: n/a
Default Re: String to char*

"Maciej" <mpap@o2.pl> schrieb:
[color=blue]
> I mean the String Class not a std::string.[/color]

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

T.M.
  #6  
Old July 23rd, 2005, 05:50 AM
Alan Johnson
Guest
 
Posts: n/a
Default Re: String to char*

Maciej wrote:[color=blue]
> Użytkownik "Leon Mergen" <lmergen@gmail.com> napisał w wiadomości
> news:1120479782.7799.1.camel@localhost.localdomain ...
>[color=green]
>>On Mon, 2005-07-04 at 14:09 +0200, Maciej wrote:
>>[color=darkred]
>>>Can I convert type String to char* ??
>>>I need to use fstream in my application together with openfiledialog.[/color]
>>
>>std::string foo = "bar";
>>char * wombat = strdup ( foo.c_str() );
>>
>>Regards,
>>
>>Leon Mergen
>>[/color]
>
> I mean the String Class not a std::string.
>
> Regards,
>
> Maciek[/color]

(Reordered to undo top-posting.)

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

-Alan
  #7  
Old July 23rd, 2005, 05:50 AM
Rolf Magnus
Guest
 
Posts: n/a
Default Re: String to char*

Please don't top-post. Fixed.

Maciej wrote:
[color=blue][color=green][color=darkred]
>> > Can I convert type String to char* ??
>> > I need to use fstream in my application together with openfiledialog.[/color]
>>
>> std::string foo = "bar";
>> char * wombat = strdup ( foo.c_str() );[/color]
>
> I mean the String Class not a std::string.[/color]

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.

  #8  
Old July 23rd, 2005, 05:50 AM
Maciej
Guest
 
Posts: n/a
Default Re: String to char*

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" <kbuchegg@gascad.at> napisal w wiadomosci
news:42C92D57.522C271E@gascad.at...[color=blue]
> Maciej wrote:[color=green]
> >
> > I mean the String Class not a std::string.[/color]
>
> 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
> kbuchegg@gascad.at[/color]


  #9  
Old July 23rd, 2005, 05:50 AM
Maciej
Guest
 
Posts: n/a
Default Re: String to char*

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

Maciek

Uzytkownik "Rolf Magnus" <ramagnus@t-online.de> napisal w wiadomosci
news:dabamj$lqb$01$1@news.t-online.com...[color=blue]
> Please don't top-post. Fixed.
>
> Maciej wrote:
>[color=green][color=darkred]
> >> > 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() );[/color]
> >
> > I mean the String Class not a std::string.[/color]
>
> 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.
>[/color]


  #10  
Old July 23rd, 2005, 05:50 AM
benben
Guest
 
Posts: n/a
Default Re: String to char*

> I want to write a simple application using openfiledialog, and fstream.[color=blue]
> 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).[/color]

Try System::String::ToCharArray()

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemstringclasstochararraytopic.asp


  #11  
Old July 23rd, 2005, 05:50 AM
Maciej
Guest
 
Posts: n/a
Default Re: String to char*

Form1.h(79): error C2664: 'void
std::basic_ifstream<_Elem,_Traits>::open(const char
*,std::_Iosb<_Dummy>::openmode,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" <benhongh@hotmail.com> napisał w wiadomości
news:42c93442$0$20023$afc38c87@news.optusnet.com.a u...[color=blue][color=green]
> > 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).[/color]
>
> Try System::String::ToCharArray()
>
>[/color]
http://msdn.microsoft.com/library/de...us/cpref/html/[color=blue]
> frlrfsystemstringclasstochararraytopic.asp
>
>[/color]


  #12  
Old July 23rd, 2005, 05:50 AM
benben
Guest
 
Posts: n/a
Default Re: String to char*

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


  #13  
Old July 23rd, 2005, 05:50 AM
Peter Julian
Guest
 
Posts: n/a
Default Re: String to char*


"Maciej" <mpap@o2.pl> wrote in message
news:daba0g$gha$1@korweta.task.gda.pl...[color=blue]
> I mean the String Class not a std::string.
>
> Regards,
>[/color]

Then why ask here? String is proprietary. std::string and std::wstring are
part of the standard.

  #14  
Old July 23rd, 2005, 05:51 AM
Shaun
Guest
 
Posts: n/a
Default Re: String to char*

what you want can be found here:

http://blogs.msdn.com/slippman/archi...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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.