- #1
member 428835
When trying to compile the following c++ code I get the errors I've screenshot
. I'm using mac VS code, and you can see I've turned on c++11. Not sure what the issue is; any suggestions?
cpp11 turned on (I think):
errors:
C++:
// p12
#include <iostream>
#include <vector>
#include <string>
#include <map>
class Solution {
private:
std::vector<int> num = {1,4,5,9,10,40,50,90,100,400,500,900,1000};
std::vector<std::string> sym = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
int i = sym.size();
std::string result = "";
public:
std::string intToRoman(int number) {
while(number>0)
{
int div = number/num[i];
number = number%num[i];
while(div--)
{
result += sym[i];
}
i--;
}
return result;
}
};
int main()
{
int num_ = 58;
Solution ob1;
auto sol = ob1.intToRoman(num_);
std::cout << sol << "\n";
// Solution* ptr;// = &ob1;
// ptr = &ob1;
// int a = ptr->intToRoman(num_);
// std::cout << a << "\n";
// std::shared_ptr<Solution> ptr2 = std::make_shared<Solution>();
// int b = ptr2->intToRoman(num_);
// std::cout << b << "\n";
return 0;
}
cpp11 turned on (I think):
errors: