-2

ファイルの順序を逆にして、別のファイルに出力する必要があります。たとえば、

入力:

hello
this is a testing file again
just    so    much  fun

期待される出力:

just    so    much  fun
this is a testing file again 
hello

これは私の現在のコードです。行の順序だけでなく、各単語の文字の順序も逆にする場所に出力されます。

現時点の:

nuf  hcum    os    tsuj
 niaga elif gnitset a si siht
olleh

int print_rev(string filename, char c){
  ifstream inStream (filename);
  ofstream outStream;
  inStream.seekg(0,inStream.end);
  int size = inStream.tellg();
  outStream.open("output.txt");

  for (int j=1; j<=size; j++){ 
    inStream.seekg(-j, ios::end);
    c=inStream.get();
    outStream << c;
  }

  inStream.close();
  outStream.close();
  return 0;
}
4

1 に答える 1