From text file to combobox to textbox

Hello! I code in windows form application c++ and need help with following:

I have the following code inserted to read the a file:

std::fstream myfile;
myfile.open("text.txt", std::fstream::in);

**`text.txt` Includes:**

Item 10 45 123 12
It3m 54 12 1341 12
Itum 123 43 65 76


I need help with coding in values for the items in the text.txt file
and writing them out in following textboxes's as I select item in a combobox


Edit::

Codings I have done and errors I get.

I am using VC++ with CLR

I will show you what I have coded so far:

My window:

Image uploaded at mediafire
http://www.mediafire.com/convkey/1b6d/d7zbqb34kv80t2bfg.jpg


When I select something it should write as such:

Image uploaded at mediafire
http://www.mediafire.com/convkey/3da7/t4s2zoibxulvf5yfg.jpg


My current code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#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
Last edited on
You mean MFC?

Aceix.
Sorry, have edited my topic as I was not clear what I needed help with.

No I am using CLR VC++ Windows form application
Last edited on
Topic archived. No new replies allowed.