ANIRUDDHA GUIN
ANIRUDDHA GUIN

Reputation: 15

No matching error operator error in string input?

I am learning about vector pairs, mostly I can take other datatypes easily but while taking string as input it always shows no matching operator>> error at the cin>>s statement, I am attaching a small snippet of the code (its incomplete though for purpose)-

    #include <iostream>
    #include <string>
    #include <vector>
    #include <utility>


    using namespace std;

    int main()
    {
    int T;
    cin>>T;
    while(T--)
    {
    unsigned int N;
    cin>>N;
    vector <pair<int,string>> v(N);
    for(unsigned int i = 0;i<N;i++)
    {
       string s[200];
       cin>>s;
       v[i].make_pair(i+1,s);
    }


    }
    return 0;
    }

Upvotes: 0

Views: 57

Answers (2)

Mahesh Nepal
Mahesh Nepal

Reputation: 1439

Declaring an array for storing a single string does not make sense here. For your purposes you can simply declare a normal string variable as:

for(unsigned int i = 0;i<N;i++)
{
    string s;
    cin>>s;
    v[i].make_pair(i+1,s);
}

Upvotes: 1

SR810
SR810

Reputation: 228

You have basically made an array of string by using the statement string s[200]; Taking an input in s is basically meaningless here. You would have to take an input in a particular index of s. Something like cin>>s[0]

Another error is when you make a pair, the type you have specified for the pair is <int,string>. The pair you make here will be <int,string*>

Upvotes: 0

Related Questions