0

Below is the code getline(cin,s) not reading the string for the below example

enter image description here

    //https://codeforces.com/problemset/problem/266/A
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        string s;
        int n, c = 0;
        cin >> n;
        getline(cin, s);
        char fc = s[0];
        for (int i = 1; i <= s.length(); i++)
        {
            if (s[i] == fc)
            {

                ++c;
            }
            else{
                fc = s[i];
            }
        }
        cout << c;
    }
john
  • 71,156
  • 4
  • 49
  • 68
  • It is reading a string, just not the string you are expecting it to read. It's reading the string that starts after the `3` and goes to the end of that line, not the string starting with `RRG` on the next line. – john Apr 26 '20 at 12:40
  • got it `getline(cin.ignore() ,s)` will work, thanks @john – sarvesh kumar Apr 26 '20 at 12:49

0 Answers0