print the all information to my file.dat
Oct 26, 2014 at 5:34pm UTC
hey still working on my coding as the coding state if I type 1 it will print my output and I want create the .dat file print my name, gender, age to my .dat what if i write under the if statement in order in print my output?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include <iostream>
#include <string>
#include<stdio.h>
#include<stdlib.h>
int main()
{
printf("Welcome to the CS227 Heath Record System\n" );
std::string a;
std::string b;
int c;
char d;
int e;
FILE *out;
std::cout << "Enter your first name: " ;
std::cin >> a;
std::cout << "Enter your last name: " ;
std::cin >> b;
std::cout<< "Enter your gender:" ;
std::cin>>d;
std::cout<< "Enter your age:" ;
std::cin>> c;
printf("To Output Biometrics: Type \n" );
printf("To Quit <without saving>: Type q\n" );
std::cout<< "Selction >" ;
std::cin>> e;
if (e == 1)
else
return0;
}
Oct 26, 2014 at 5:48pm UTC
Open a output stream and send to it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <iostream>
#include <string>
#include <fstream>
int main()
{
std::ofstream output;
std::string str;
output.open("file.dat" );
if (output.fail()){
std::cerr << "File creation failed.\n" ;
return 1;
}
std::cout << "Enter name: " ;
std::getline(std::cin, str);
output << str << std::endl;
output.close();
return 0;
}
Topic archived. No new replies allowed.