This the first lab of many with an introduction back into C++ programming.
It has the basic input output using IOStream as well as reading in and out of a file.
#include <iostream>
#include <fstream>
using namespace std;
void example4();
void exampleFiles();
int main()
{
exampleFiles();
cout << "enter an int to finish";
int x;
cin >> x;
return 0;
}
void exampleFiles()
{
int number;
char ch;
float fl;
fstream myFile("output.txt", ios::out | ios::in | ios::app);
cout << "enter a integer" << "\n";
cin >> number;
myFile << "You have entered the number " << number << "\n";
cout << "Enter a character" << "\n";
cin >> ch;
myFile << "you entered " << ch << "\n";
cout << "Enter a float" << "\n";
cin >> fl;
myFile << "you entered " << fl << "\n\n";
fstream myInputFile("input.txt", ios::out | ios::in | ios::app);
myInputFile >> number;
myInputFile >> ch;
myInputFile >> fl;
std::cout << "in Summary you have entered " <<number << ", " << ch << " & " <<fl << "\n";
myFile.close();
myInputFile.close();
}
void example4()
{
int number;
char ch;
float fl;
cout << "Enter a integer" << "\n";
cin >> number;
cout << "You have entered the number " << number << "\n\n";
cout << "Enter a character" << "\n";
cin >> ch;
cout << "you entered " << ch << "\n\n";
cout << "Enter a float" << "\n";
cin >> fl;
cout << "you entered " << fl << "\n\n";
std::cout << "in Summary you have entered " <<number << ", " << ch << " & " <<fl << "\n";
}
No comments:
Post a Comment