0
#pragma once
#include <fstream>

namespace testrun1 {

    using namespace System;
 using namespace System::ComponentModel;
 using namespace System::Collections;
 using namespace System::Windows::Forms;
 using namespace System::Data;
 using namespace System::Drawing;
 using namespace System::IO;
 using namespace std;
 #pragma endregion
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

 ifstream inputFile; 
 ofstream outputFile; 



 inputFile.open("1.txt"); 
 outputFile.open("sum.txt"); 

 int num1;
 int num2;
 inputFile >> num1;

 inputFile.close();

 inputFile.open("1a.txt");
 inputFile >> num2;

int sum;
 sum = (num1 + num2);

 outputFile << sum;
 outputFile.close();

             }
    };
}

// for some reason I keep getting the wrong value in sum.txt
// if 1.txt has the value of 10 and 1a.txt has the value of 10, I will get the sum of 16789978!
// HOW DO I FIX THIS????

2
Contributors
1
Reply
8
Views
4 Years
Discussion Span
Last Post by Ancient Dragon
0

See the example here. Delete fstream from your program because it won't work with Windows Forms, which is CLR/C++, not c++, two different languages.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.