M.CORP Grandmaster Cheater Supreme
Reputation: 28
Joined: 28 Oct 2009 Posts: 1010
|
Posted: Mon Sep 12, 2011 2:57 am Post subject: [C++]Questions about input and output with files |
|
|
CPP file:
Code: | #include "stdafx.h"
using namespace std;
int main () {
string fileE;
ofstream myfile ("example.txt");
ifstream myfile1 ("example.txt");
if (myfile.is_open()){
myfile << "Hello there USER! :P\n";
myfile.close();
getline (myfile1, fileE);
cout << fileE << endl;
}
else {
cout << "Unable to open D:!\nCreating a new one!\n";
myfile << "asfasdf!";
}
cin.get();
return 0;
} |
Header file:
Code: | #pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std; |
In this example, can i declare fstream only by itself without declaring iostream to achieve the same result as the above without using of/ifstreams? _________________
|
|