Why does it say my "to_string" was not declared in this scope?

Error on line 20, 36, 44, 52, 68, 76, 82

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106


string polynomials::toString()
{
    
    string temp;
    
    if (polyVect.size()==0) {
        
        temp = temp+ " 0";
    }
    
    //For loop goes through each element and appends it to a single string
    for (int i = 1; i <= polyVect.size(); i++)
    {
        //Case for nx^0 becomes n
        if (polyVect.at(i-1).pow == 0 && polyVect.at(i-1).coeff > 1)
        {
            
            temp = temp + " + " + to_string(polyVect.at(i-1).coeff);
            
        }
        
        //Case for 1x^1 becomes x
        else if (polyVect.at(i-1).pow == 1 && polyVect.at(i-1).coeff == 1)
        {
            
            temp = temp + " + x";
            
        }
        
        //Case for nx^1 becomes nx
        else if (polyVect.at(i-1).pow == 1 && polyVect.at(i-1).coeff > 1)
        {
            
            temp = temp + " + " + to_string(polyVect.at(i-1).coeff)+ "x";
            
        }
        
        //Case for 1x^n becomes x^n
        else if (polyVect.at(i-1).pow != 1 && polyVect.at(i-1).coeff == 1)
        {
            
            temp = temp +  " + x^" + to_string(polyVect.at(i-1).pow);
            
        }
        
        //Case for -nx^0 becomes -n
        if (polyVect.at(i-1).pow == 0 && polyVect.at(i-1).coeff < -1)
        {
            
            temp = temp + " - " + to_string(-(polyVect.at(i-1).coeff));
            
        }
        
        //Case for -1x^1 becomes -x
        else if (polyVect.at(i-1).pow == 1 && polyVect.at(i-1).coeff == -1)
        {
            
            temp = temp + " - x";
            
        }
        
        //Case for -nx^1 becomes -nx
        else if (polyVect.at(i-1).pow == 1 && polyVect.at(i-1).coeff < 0)
        {
            
            temp = temp + " - " + to_string(-(polyVect.at(i-1).coeff))+ "x";
            
        }
        
        //Case for -1x^n becomes -x^n
        else if (polyVect.at(i-1).pow != 1 && polyVect.at(i-1).coeff == -1)
        {
            
            temp = temp +  " - x^" + to_string(polyVect.at(i-1).pow);
            
        }

        else if(polyVect.at(i-1).coeff < 1 && polyVect.at(i-1).pow > 1)
        {
            temp = temp + " - "+ to_string(-(polyVect.at(i-1).coeff))
            + "x^" + to_string(polyVect.at(i-1).pow);
            
        }
        
        //Case for the rest becomes nx^n
        else if(polyVect.at(i-1).coeff > 1 && polyVect.at(i-1).pow > 1)
        {
            temp = temp + " + "+ to_string(polyVect.at(i-1).coeff)
                        + "x^" + to_string(polyVect.at(i-1).pow);
            
        }
    }
    
    if (polyVect.at(0).coeff > 1)
    {
        temp.replace(0, 3, "");
    }
    else if (polyVect.at(0).coeff < 1)
    {
        temp.replace(0, 3, "-");
    }
    
    return temp;
}
Last edited on
Have you used -std=c++11 ? If you have, then I have no idea
Try changing to_string to std::to_string
Topic archived. No new replies allowed.