
simple file Input/output
By:
DarkShadowsX5 on
May 7th, 2012 | syntax:
C++ | size: 0.56 KB | hits: 17 | expires: Never
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ofstream outputFile("file.txt"); //ofstream will create the file if it doesnt exist, ifstream will not.
ifstream inputFile;
char myString[50];
cout << "file.txt \n";
cout << "Enter a string: ";
cin.getline( myString, 50, '\n');
cout << "Writing string to file...\n";
outputFile << "\n world";
outputFile << myString;
outputFile.close();
cout << "Reading string from file...\n";
inputFile.open("File.txt");
cout << myString;
return 0;
}