Sunday, February 5, 2017

Saving two values in text file in C++

Here is a simple program that I wrote that will save the two values in a text file using C++ as our programming language. The code is very short and easy to understand.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.


Program Listing

#include <iostream>
#include <fstream>

 using namespace std;

  class test {
      public:

       int x,y;
  };

  main() {
      test values;
      int solve=0;
   ofstream myfile("result.txt");
  cout << "Enter two numbers : ";
  cin >> values.x >> values.y;
  cout << "\n\n";
  solve = (values.x) + (values.y);
  cout << "The sum is " << solve;
  cout << "\n\n";
  myfile << "\t Result";
  myfile << "\n\n";
  myfile << "The sum is " << solve << ".";
  myfile.close();
  }

No comments:

Post a Comment