473,412 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

String to char*

Hallo,

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

Thanks,

Maciek
Jul 23 '05 #1
13 4706
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

Jul 23 '05 #2
I mean the String Class not a std::string.

Regards,

Maciek

Użytkownik "Leon Mergen" <lm*****@gmail.com> napisał w wiadomości
news:11*********************@localhost.localdomain ...
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

Jul 23 '05 #3
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
kb******@gascad.at
Jul 23 '05 #4
"Maciej" <mp**@o2.pl> 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.
Jul 23 '05 #5
Maciej wrote:
Użytkownik "Leon Mergen" <lm*****@gmail.com> napisał w wiadomości
news:11*********************@localhost.localdomain ...
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
Jul 23 '05 #6
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.

Jul 23 '05 #7
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" <kb******@gascad.at> napisal w wiadomosci
news:42***************@gascad.at...
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
kb******@gascad.at

Jul 23 '05 #8
I have tried msdn.com, but it is very hard for me to find a relevant
function.

Maciek

Uzytkownik "Rolf Magnus" <ra******@t-online.de> napisal w wiadomosci
news:da*************@news.t-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.

Jul 23 '05 #9
> 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/de...us/cpref/html/
frlrfsystemstringclasstochararraytopic.asp
Jul 23 '05 #10
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" <be******@hotmail.com> napisał w wiadomości
news:42***********************@news.optusnet.com.a u...
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/de...us/cpref/html/ frlrfsystemstringclasstochararraytopic.asp

Jul 23 '05 #11
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
Jul 23 '05 #12

"Maciej" <mp**@o2.pl> wrote in message
news:da**********@korweta.task.gda.pl...
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.

Jul 23 '05 #13
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.

Jul 23 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Gaurav | last post by:
Hello, I am using visual c++ 6 and i am having problems with string to work. ******** Here is the program project.cpp********* #include <iostream.h> #include <string> #include "stdafx.h"
2
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
7
by: Forecast | last post by:
I run the following code in UNIX compiled by g++ 3.3.2 successfully. : // proj2.cc: returns a dynamic vector and prints out at main~~ : // : #include <iostream> : #include <vector> : : using...
13
by: M | last post by:
Hi, I've searched through the previous posts and there seems to be a few examples of search and replacing all occurrances of a string with another string. I would have thought that the code...
16
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
6
by: becte | last post by:
I am little bit confused Is this a legal way of removing a substring from a string? What about the second alternative using strcpy, is it ok even though the source and dest. strings overlap? ...
3
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.