Some Gourment SHIT with .size() in C++ . Why ?

Правка en1, от kazuya, 2020-06-18 12:07:16

This is a short code which I wrote and it only printed '1' and not "Hello World" but when I did typecasting in if statement i.e if((int) it->second.size() > x) then it worked completely fine. Now if typecasting is the solution then why this line always works " for (int i=0;i < v.size(); i++) ". Please can anyone explain this behaviour ?

Your code here...
#include<bits/stdc++.h>
using namespace std;


int main()
{
    map<int,set<int>> m;
    m[0].insert(1);
    
    int x = -1;
    for(auto it=m.begin();it!=m.end();it++)
    {
        cout<<it->second.size()<<endl;  
        if(it->second.size() > x)
        cout<<"Hello World"<<endl;
    }
}
Теги #c++, size

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский kazuya 2020-06-18 12:08:04 1
en1 Английский kazuya 2020-06-18 12:07:16 750 Initial revision (published)