Posts

Showing posts with the label file

File Handling in Python

Image
This is the post in which you will learn about the Files in Python. Basically you can, by using this post learn how to create a file, write data and read data from it ! Screenshot Things this code will do: Create a Folder Test Changes the Current Working Directory Creates a file as per your given name Stores the Data you give as input Shows the Data you gave as input The Code: import os # Create a Directory and make it as working dir. os.mkdir("test") os.chdir("test") print "current working Dir: ",os.getcwd() name=raw_input("Give the Name: ") # Open a file and writing into it fo = open(name, "w+") fo.write(raw_input("Give the Data : ")) fo.close() # Open a file and reading it fo = open(name, "r+") str = fo.read(); print "Read The Data :",str fo.close() Got problems ? Ask us anything anytime, we will help you soon !

Merging two files into one file

Image
Some time we need to merge two or more file written by many ones. Then we can simply use such a lite and small program to merge many files into one. Screenshots: The output of the program View of the file one View the file two View the merged file here The code: #include<iostream> #include<fstream> #include<string.h> using namespace std; int main(int argc, char *argv[]) { if ( argc != 4 ) cout<<"give 3 file as command line argument"<<endl; else { ifstream file1; /*object created for file1*/ file1.open(argv[1]); /*Name of the file1 passed through command line argument*/ string line1; /*String is created to store all the data of the file1*/ char c1 = file1.eof(); /*EOF file1 is stored in a character variable*/ getline(file1,line1,c1); /*scanning and storing the data into the string*/ cout<<"The first file is opening here:\n\n"; cout<<line1<<endl; /*Simil...