tags:

views:

67

answers:

2
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main(int argc,char *argv){
fstream inout("C:\\Users\\7\\Desktop\\test.txt",ios::in | ios::out | ios::binary);
if (!inout){
 cout<<" cannot open input file.\n";
  return 1;

}

long e,i,j;
char c1,c2;
e=5;
 for (i=0,j=e;i<j;i++,j--){


  inout.seekg(i,ios::beg);
  inout.get(c1);
  inout.seekg(j,ios::beg);
  inout.get(c2);
  inout.seekp(i,ios::beg);
  inout.put(c2);
  inout.seekg(j,ios::beg);
  inout.put(c1);
 }


 inout.close();



 return 0;
}

why this code writes can't open file EDIT: i have made corrections but here is one problem in test.txt is written such thing

maiko
miyvarxar
shen
me

so it should write me shen miyvarxar maiko but it does not write anything please help

A: 

The code you've provided looks fine.

You may have supplied the wrong path or something like that.

You could also try attempting to open that file in read only mode and see if that is ok:

std::ifstream in("path", std::ios::binary);

if (!in) {
   // fail
}
HardCoder1986
+2  A: 

This seems to work for me:

using namespace std;
int main() 
{ 
  fstream inout("C:\\Users\\turdfurguson\\Turds\testfile.txt", ios::in | ios::out | ios::binary);
  if (inout.good())
    cout << "OK!" << endl;
}

Provided you have a "C:\Users\turdfurgson\Turds\testfile.txt" file that is readable and writable.

turdfurguson
my dekstop full path is this C:\Users\7\Desktop> please help me
does the "test.txt" file exists?
turdfurguson
yes sure it exists
try ", ios::in | ios::binary); what is result?
turdfurguson
Oh man, I almost want to +1 you for your name and path choice.
GigaWatt