Skip to content

Instantly share code, notes, and snippets.

@andraantariksa
Last active April 18, 2019 07:07
Show Gist options
  • Save andraantariksa/da676654af4b39f2b36c9d0ef4b16717 to your computer and use it in GitHub Desktop.
Save andraantariksa/da676654af4b39f2b36c9d0ef4b16717 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <iomanip>
int main(int argc, const char *argv[]){
std::string name, surname, city;
std::fstream file;
file.open("output.txt", std::fstream::in | std::fstream::out | std::fstream::app);
std::cout << "Write the detail with these format. Press <Ctrl+D> to send EOF to program.\nName Surname City\n";
if(file.peek() == std::ifstream::traits_type::eof()){
file << std::left << std::setw(10) << "Name" << std::setw(15) << "Surname" << std::setw(15) << "City" << '\n';
}
while(std::cin>> name >> surname >> city){
file << std::left << std::setw(10) << name << std::setw(15) << surname << std::setw(15) << city << '\n';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment