String to char*

M

Maciej

Hallo,

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

Thanks,

Maciek
 
L

Leon Mergen

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
 
A

Alan Johnson

Maciej said:
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
 
K

Karl Heinz Buchegger

Maciej said:
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.
 
T

Torsten Mueller

Maciej said:
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.
 
M

Maciej

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
 
M

Maciej

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

Maciek
 
R

Rolf Magnus

Please don't top-post. Fixed.
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.
 
M

Maciej

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.
 
B

benben

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
 
P

Peter Julian

Maciej said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top