Getline issues

Im trying to write a class that will equip an item (move it to equipt in a text document from inventory) but when ever i run the program i get the error: no matching function for call to 'getline(std::istringstream&, int&)' also another error: no match for 'operator==' in 'name==item'

I have all of the includes and variables listed. Here is the 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//Variables
int money;
int slotnum;
string Playername;
string Side;
string temp;
string DisplayText;
int StartScreenChoice;
int Strength;
int Health;
int Stamina;
int Magic;
string SpecialPower;
int Defence;
int value;
int ClassPick;
int item;
string EquipItem;
string temp2;
string name;
int value2;
string name2;
//Functions
int Pack();
int DOSwindow();
int TheBeginning();
int ChooseClass();
//Classes
    /*-------------Equipped Items-------------*/
class ItemEquip
{
      public:
             int Head()
             {
                string wantitem;
                ifstream inventory("invintory.txt");
                cout << "Enter Choice" <<endl;
                cin >> name;
                while( getline( inventory, temp2 ) )
                {
                       istringstream liness(temp2);
                       getline(liness,item);
                       
                       if (name == item)
                       {
                                     cin >> wantitem;
                                     ifstream inventory("invintory.txt");
                                     
                                     while( getline( inventory, temp2 ) )
                                     {
                                     istringstream liness(temp2);
                                     getline(liness, name2, ' ');
 
                                     if (wantitem == name2)
                                     {
                                           cout << endl;
                                           cout << "Item: " << name2 << endl;
                                           cout << endl;
                                           cout << "Are you sure you want to buy? " << endl;
                                           string respo;
                                           cin >> respo;
                                           if (respo == "yes")
                                           {

                                              
                                              
                                                  ofstream tempfile("temp.txt");
                                                  ofstream secondfile("invintory.txt",ios::app);
                                                  ifstream secondfile2("invintory.txt");
                                                  
                                                  
                                                  if (secondfile2.is_open() )
                                                  {
                                                     vector<string> text_file;
                                                     string temp;
                                                     string temp2;
                         
                         
                                                     while( getline( secondfile2, temp ) )
                                                     {
                                
                                
                                                         istringstream liness(temp);
                                                         getline(liness,item, ' ');
                               
                                                         if (name2 == item)
                                                         {
                                                             
                                                             tempfile << temp << " done" << endl;
                                                             
                                                         }
                                                         if(name2 != item)
                                                         {
                                                             tempfile << temp << endl;
                                 
                                                         }
                              
                                                         text_file.push_back( temp );
    
                                                      }
                                                  
                                                  inventory.close();
                                                  tempfile.close();
                                                  secondfile.close();
                                                  secondfile2.close();
                                                  remove("invintory.txt");
                                                  rename("temp.txt","invintory.txt");
                                                  
                                                  ifstream ArmorUp("equipped.txt");
                                                  ofstream tempfile2("temp2.txt");
                                                  if (ArmorUp.is_open() )
                                                  {
                                                     vector<string> text_file;
                                                     string temp;
                                                     string temp2;
                         
                                                     string name;
                         
                                                     while( getline( ArmorUp, temp ) )
                                                     {
                                
                                
                                                         istringstream liness(temp);
                                                         getline(liness,item);
                               
                                                         tempfile2 << temp << endl;
                              
                                                         text_file.push_back( temp );
    
                                                      }
                                                      
                                                      tempfile2 << name2 << endl;
                                                      tempfile2.close();
                                                      ArmorUp.close();
                                                      remove("equipped.txt");
                                                      rename("temp2.txt","equipped.txt");
                                                  }
                                                  }
                                                  }
                                              
                                                   
                                                                    
                                              
                                           
                                           if (respo == "no")
                                           {
                                              return 0;
                                              inventory.close();
                                           }
                                           }
                                           }
    }
    }
}
      
};
getline(liness,item);

The second parameter, item, is an int. getline doesn't take an int as the second parameter.

http://www.cplusplus.com/reference/string/getline/

if (name == item)
name is a string, item is an int. C++ does not know what to do with the == operator when you've got an int on one side and a string on the other. It only knows how to use the == operator with objects of the same type. You can either program such an operation yourself, or change your code so that the two sides are of the same type.
It is what the error tells you: item is an int and getline expects a string. And you cannot compare a string and an int.

Use << or >> if you want to associate an int with a stream. And then with the help of a stringstream you can convert int to string or vice versa
Topic archived. No new replies allowed.