this post bases on the solution given here, a post on SO
I write a function to get a given file extension (string type), something like:
void GetFileExtension(string filename, char* extension)
{
vector<string> rec;
StrDelimit(filename, '.', rec);
//cout << rec[rec.size()-2].c_str()[1] << endl;
//extension = rec[rec.size()-2].c_str()[0];
//extension = &rec[rec.size()-2].c_str()[0];
string str = rec[rec.size()-2];
// conversion from string to char*
vector<char> writable(str.size() + 1);
std::copy(str.begin(), str.end(), writable.begin());
//cout << writable << endl;
extension = &writable[0];
}
StrDelimit works fine already which receives a string and delimits to vector of substrings by the given delimiter
I use the "//conversion from string to char*" as shown to return the result to calling main program
There is no compile error but the result is a string of meaningless characters. What's it the problem?
any help would be appreciated!
Thank you!