//:How do I convert to string? C++?

pragma once
 #include <iostream>
 #include <fstream> 
#include <istream>
 #include <string>
 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;


private: int total;


#pragma endregion
 private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {


std::stringstream; 


std::ifstream ifs("1.txt");

std::string line;

while(std::getline(ifs, line));


std::ifstream ifs1("1a.txt");

std::string line1;

while(std::getline(ifs1, line1));

total = (line1 + line); 




String^ fileName = "text1.txt";
 StreamWriter^ sw = gcnew StreamWriter(fileName);
 sw->WriteLine (Convert::ToString(total));
 sw->Close();




}
 };
 }

//:The Error that I keep getting is::::

//:error C2440: '=' : cannot convert from 'std::basic_string<_Elem,_Traits,_Ax>' to 'int'

You are attempting to mix two different languages -- c++ and CLR/C++. Since you are using CLR/C++ (Windows Forms) then you must use System.io.File class instead of <iostream> and <fstream>. Forget about using standard c++ header files, they don't work with CLR/C++. Other container classses are in the compiler's include/clrext folder.

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.