Hi,
I've made a program that reads a file, sorts the content and now I want to output the result to a new file. The new file should have the same name as the old, but a different extension ('.srt').
How do I do that?
Additional question: how do I open a file in a different directory? (if I just use the full path, I get an error)
Thanks in advance,
Sunaj
Here's my code so far:
----------------------------------------------------------
int main(int argc, char *argv[])
{
const char *FileName = (argc == 2) ? argv[1] : NULL;
if (FileName == NULL)
{
cerr << "Usage: " << argv[0] << " 'filename'\n";
return 1;
}
ifstream inFile;
inFile.open(FileName, ios::in | ios::nocreate);
if (!inFile.good())
{
perror (FileName);
return 1;
}
// my manipulation is done here.
// Here I want to set NewFileName = FileName, but with new extension.
ofstream outFile(NewFileName, ios:
ut);
// the putput is written here.
}
I've made a program that reads a file, sorts the content and now I want to output the result to a new file. The new file should have the same name as the old, but a different extension ('.srt').
How do I do that?
Additional question: how do I open a file in a different directory? (if I just use the full path, I get an error)
Thanks in advance,
Sunaj
Here's my code so far:
----------------------------------------------------------
int main(int argc, char *argv[])
{
const char *FileName = (argc == 2) ? argv[1] : NULL;
if (FileName == NULL)
{
cerr << "Usage: " << argv[0] << " 'filename'\n";
return 1;
}
ifstream inFile;
inFile.open(FileName, ios::in | ios::nocreate);
if (!inFile.good())
{
perror (FileName);
return 1;
}
// my manipulation is done here.
// Here I want to set NewFileName = FileName, but with new extension.
ofstream outFile(NewFileName, ios:
// the putput is written here.
}