0

I want the output file to have the same name as the input file (with different extension) E.g: Input: packet_a.raw , Output: packet_a_data.txt

I tried saving the fileName in a string but ifstream and ofstream do not accept a string. I tried using char[] but then I have a hard time modifying it.

4

2 に答える 2

0

を使用char[]して変更することができますsprintf。そんな感じ:

ofstream outFile_raw;
ofstream outFile_txt;
std::string  data;

std::string format_raw="raw";
std::string format_txt="txt";

char fileName[20];
sprintf(fileName, "..\\Packages\\packet_a.%s", format_raw);

outFile_raw.open(fileName, ios::trunc);

if(outFile_raw.is_open())
{
     outFile_raw<< data; // Write contents of the data to the file stream.
     outFile_raw.close();
}

sprintf(fileName, "..\\Packages\\packet_a.%s", format_txt);

outFile_txt.open(fileName, ios::trunc);

if(outFile_txt.is_open())
{
     outFile_txt<< data; // Write contents of the data to the file stream.
     outFile_txt.close();
}
于 2013-04-27T20:13:50.320 に答える