Showing posts with label files. Show all posts
Showing posts with label files. Show all posts

Wednesday, 21 May 2014

files in c++



#include<iostream>
#include<conio.h>
#include<string.h>
#include<fstream>
using namespace std;
int main()
{
    ofstream out;
    out.open("temporary.txt");
    string s1,s2;
    cout<<"enter the string"<<endl;
    cin>>s1;
    cout<<"enter another string"<<endl;
    cin>>s2;
    out<<s1;
    out<<s2;
    out.close();
    ifstream in;
    in.open("temporary.txt");
    string n1;
    in>>n1;
    ofstream out1;
    out1.open("temporary1.txt");
    out1<<n1;
    out1.close();
    ifstream in1;
    in1.open("temporary1.txt");
    in1>>n1;
    cout<<n1;
    in.close();
    in1.close();
    getch();
    return 0;
}
Follow my blog with Bloglovin

Sunday, 27 April 2014

file handling


// writing on a text file
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile ("example1.txt");
  if (myfile.is_open())
  {
    myfile << "This is a line.\n";
    myfile << "This is another line.\n";
    myfile.close();
  }
  else cout << "Unable to open file";
  return 0;
}

Saturday, 26 April 2014

files in c++


#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
int main()
{
int height[4]={3,52,4,354};
ofstream temp;
temp.open("file_5.txt");
temp.write((char*) &height , sizeof(height));
temp.close();
for(int i=0;i<4;i++)
{
height[i]=0;
}
ifstream temp1;
temp1.open("file_5.txt");
temp1.read((char*) &height , sizeof(height));
for(int j=0;j<4;j++)
{
cout<<height[j]<<endl;
}
getch();    return 0;
}