0

the code below is a part of a program which makes some integer sets by using class. the member variable is called set which is a boolean vector and set[i]=true if i is in set. now we want to have the members of a set in a string in the way that each member seprates by ','. for example if in main function we have IntegerSet A and the members of A are 1,2,3 ; by using toString.A() we should have {1,2,3} in output. I have the code of this part of program but my problem is that I don't know what bool first=true exactly do and how by using it the compiler understand that we mean what? I would appreciate if anyone can help me.

std::string IntegerSet::toString(IntegerSet)
{
    std::string str;
    bool first = true;
    str += '{';
    for (int i = 0; i <= limit; i++)
    {
        if (set[i])
        {
            if (!first)
                str += ",";
            else
                first = false; 
            str += std::to_string(i);
                
        }
    }
    str += '}';
    return str;
}
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
pantea
  • 9
  • 3

0 Answers0