// Reading a file
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::string line;
std::ifstream file("example.txt");
if(file.is_open())
{
while(getline(file, line))
{
std::cout << line << '
';
}
file.close();
}
else std::cout << "Unable to open file";
return 0;
}
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("file.txt");
myfile << "Writing to a file.
";
myfile.close();
return 0;
}
#include <stdio.h>
#define n 1024 // n bytes
int main(void) {
FILE *fp;
size_t numread;
if ((fp = fopen("yourfile.xy", "rb") != NULL) {
char buffer[n];
numread = fread(buffer, sizeof(*buffer), n, fp);
printf("Read %d Bytes: %s", numread, buffer);
fclose(fp);
return 0;
}
return -1;
}
fstream afile;
afile.open("file.dat", ios::out | ios::in );