0

Wish you all a good day.Currently i'm working on c++ project.I want to know how to convert string object to a character array.Also why ifstream object doesn't accept a string variable as follows,
void split(String filename)
{
ifstream ifile;
ifile.open(filename);//this fails

}

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by VernonDozier
0

Wish you all a good day.Currently i'm working on c++ project.I want to know how to convert string object to a character array.Also why ifstream object doesn't accept a string variable as follows,
void split(String filename)
{
ifstream ifile;
ifile.open(filename);//this fails

}

A string already is a character array. See this post.
http://www.daniweb.com/forums/thread117321.html
If you want to open a file where filename is a string, you need to use the c_str () function:

ifile.open(filename.c_str ());
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.