#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????

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.