Troubleshooting with getline statement

Hello all,

I've been writing a program that asks the user to input information into a text file and then can pull up information from a certain number of previous workouts (it records fitness progress). I am designing two functions that are supposed to run through the program with a getline statement, compare it to the input by the user and then print the workout until getline recognizes a stop signal (a "|" which serves as the marker for the end of the workout).

It seems to have no real problems but both of the functions have the same error pop up which reads:

no match for 'operator==' in 'std::getline [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((std::basic_istream<char, std::char_traits<char> >&)((std::basic_istream<char, std::char_traits<char> >*)(&cardio))), ((std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)(&cardio_holder))) == "|"'

Here are the codes:

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
void cardio_search(string exercise, int times)
{
     string cardio_holder;
     int n = 0;
     
     fstream cardio;
     cardio.open("cardio.txt");
     
     while (n =! times)
     {
          getline(cardio,cardio_holder);
          cout << cardio_holder << endl;
          
          if (getline(cardio,cardio_holder)== "|")
             {
                                    n++;
             }        
     }
}
     
void weightlifting_search(string exercise, int times)
{
     string weight_holder;
     int n = 0;
     
     fstream weights;
     
     getline(weights, weight_holder);
     weights.open("weights.txt");
     
     while (n != times)
     {
          if (getline(weights, weight_holder) = exercise)
          {
                cout << weight_holder << endl;
                
                if (weight_holder == "|")
                {
                                  continue;
                }
          n++;
          }
          
     }
}




Thanks for your time and help in advance!

std::getline returns a reference to the stream object you pass as the first argument. What you probably want to do is to first read the string with getline and then afterwards check the string operator==.
getline returns a reference to the stream object, not the string.
See http://www.cplusplus.com/reference/string/getline/
Thanks a bunch! I can' believe that I overlooked that.
Topic archived. No new replies allowed.