Connecting Tech Pros Worldwide Forums | Help | Site Map

String to char*

Maciej
Guest
 
Posts: n/a
#1: Jul 23 '05
Hallo,

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

Thanks,

Maciek



Leon Mergen
Guest
 
Posts: n/a
#2: Jul 23 '05

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

Maciej
Guest
 
Posts: n/a
#3: Jul 23 '05

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]


Karl Heinz Buchegger
Guest
 
Posts: n/a
#4: Jul 23 '05

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
Torsten Mueller
Guest
 
Posts: n/a
#5: Jul 23 '05

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.
Alan Johnson
Guest
 
Posts: n/a
#6: Jul 23 '05

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
Rolf Magnus
Guest
 
Posts: n/a
#7: Jul 23 '05

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.

Maciej
Guest
 
Posts: n/a
#8: Jul 23 '05

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]


Maciej
Guest
 
Posts: n/a
#9: Jul 23 '05

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]


benben
Guest
 
Posts: n/a
#10: Jul 23 '05

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


Maciej
Guest
 
Posts: n/a
#11: Jul 23 '05

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]


benben
Guest
 
Posts: n/a
#12: Jul 23 '05

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


Peter Julian
Guest
 
Posts: n/a
#13: Jul 23 '05

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.

Shaun
Guest
 
Posts: n/a
#14: Jul 23 '05

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.

Closed Thread