#include <string>
#include <fstream>
#include <istream>
#include <streambuf>
#include <iostream>
#include <sstream>
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
std::ifstream myfile;
myfile.open("text.txt", std::ifstream::in); //Reading txt file
if(myfile.is_open())
{
MessageBox::Show("File is open"); //checking if txt file loaded
}else
{
MessageBox::Show("File is not open"); //loading failed
}
//strings to use as values for items in txt
String^ itemname;
int value1;
int value2;
int value3;
int value4;
while(myfile >> itemname >> value1 >> value2 >> value3 >> value4)
// which I used to work in windows console application VC++ Win32
}
private: System::Void comboBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
//test label
label1->Text = comboBox1->Text; //itemname
//Testing out giving values to textboxes manually
if(comboBox1->Text == "Item")
{
textBox1->Text = "10"; //value1
textBox2->Text = "45"; //value2
textBox3->Text = "123"; //value3
textBox4->Text = "12"; //value4
}
if(comboBox1->Text == "It3m")
{
textBox1->Text = "54";
textBox2->Text = "12";
textBox3->Text = "1341";
textBox4->Text = "12";
}
if(comboBox1->Text == "Itum")
{
textBox1->Text = "123";
textBox2->Text = "43";
textBox3->Text = "65";
textBox4->Text = "76";
}
}
The error I get:
1 2
Error 2 error C1903: unable to recover from previous error(s); stopping compilation c:\c++\readingtxtfile2\readingtxtfile2\Form1.h 238
Error 1 error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::ifstream' (or there is no acceptable conversion) c:\c++\readingtxtfile2\readingtxtfile2\Form1.h 238