Transpose File

I dont know how to transpose the file then write it in the output file

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
#include<sstream>
using namespace std;
const int arxSize = 10;
ifstream inFile;
int i, ID = 0;




int main()
{
string b = "";
string ifilename, line, ofilename;
ifstream inFile, checkOutFile;
ofstream outFile;
char response;
// Input file
cout << "Please enter the name of the file you wish to open : ";
cin >> ifilename;
inFile.open(ifilename.c_str());
if (inFile.fail())
{
cout << "The file " << ifilename << " was not successfully opened." << endl;
cout << "Please check the path and name of the file. " << endl;
exit(1);
}
else
{
cout << "The file is successfully opened." << endl;
}
// Output file
cout << "Please enter the name of the file you wish to write : ";
cin >> ofilename;
checkOutFile.open(ofilename.c_str());
if (!checkOutFile.fail())
{
cout << "A file " << ofilename << " exists.\nDo you want to continue and overwrite it? (y/n) : ";
cin >> response;
if (tolower(response) == 'n')
{
cout << "The existing file will not be overwritten. " << endl;
exit(1);
}
}
outFile.open(ofilename.c_str());
if (outFile.fail())
{
cout << "The file " << ofilename << " was not successfully opened." << endl;
cout << "Please check the path and name of the file. " << endl;
exit(1);
}
else
{
cout << "The file is successfully opened." << endl;
}
// Copy file contents from inFile to outFile

cout << "Please enter the last 5 digits in your student ID : ";
cin >> ID;
cout << " " << endl;
cout << "The numbers from the input file with added last row." << endl;
while (getline(inFile, line))
cout << line << endl;

if (ID < 0)
ID = -ID;
stringstream ss;
ss << ID; //convert to individual numbers
ss >> b;
for (int i = 0; i < b.length(); ++i)
{
cout << b[i] << " ";
}
cout << " " << endl;



inFile.close();
outFile.close();
} // main
Last edited on
The word "transpose" means to swap, so I guess my first question is what do you want to transpose the source file with?
3 7 2 9 0
1 8 4 6 5
0 2 7 4 3
6 1 9 5 8
with the added ID = 24161
is what I want to transpose and write to the output file
No I have to transpose it
Topic archived. No new replies allowed.