Jan 5, 2016 at 8:18pm UTC
So I have the following code To Prompt for filename:
cout << "Please enter the filename for the report: ";
cin >> filename;
ConvertToUpper(filename);
Then create a new file with the name provided:
int row, col, space;
char str[3];
ofstream report(filename);
if (report.fail())
{
cout << "This is Pascal's triangle for the power of " << power << "\n\n\n";
for (row = 0; row <= power; row++)
{
for (space = 0; space < 37 - (row * 3); space++);
{
report << " ";
}
for (col = 0; col <= row; col++)
{
report << setw(6) << pascal_tri[row][col];
}
report << endl;
}
report.close();
}
else
{
cout << "Unable to open the file";
cout << "\n\nPress the enter key to try again";
cin.ignore(cin.rdbuf()->in_avail());
cin.getline(str, 2, '\n');
cin.ignore(cin.rdbuf()->in_avail());
}
But The output file have no file extensions, how do I add ".txt" to a char[]?
Please help....
Last edited on Jan 5, 2016 at 8:18pm UTC
Jan 5, 2016 at 8:38pm UTC
Appending to char[] is strcat's job from <cstring>
http://www.cplusplus.com/reference/cstring/strcat/
Welcome to cplusplus.com! Whenever you post code, please use code tags. You can get them by clicking the <> button to the right of the text box while editing.
Edit: I also suggest coming into the future by using std::string instead of the old <cstring>
Edit2: Chervil beat me to it :P
Last edited on Jan 5, 2016 at 8:46pm UTC
Jan 5, 2016 at 9:15pm UTC
Thank you guys very much~