We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Mine wors in my compiler, but when I put the exact same code in the Hackerank compiler, it gives me the wrong answer. Very bizarre:
classStudent{std::vector<int>scores{};public:voidinput(){// If std::cin buffer has '\n', then clear the bufferif(std::cin.peek()=='\n'){std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');}std::stringstr;//read input and store it in a string "str", note that this includes the newline character '\n';std::getline(std::cin,str);//a way to remove the newline from the stringstd::stringstreamiss(str);//convert the numbers on the string to an integers and store it as elements of vector str_intintscore;while(iss>>score){scores.emplace_back(score);}}intcalculateTotalScore(){inttotal{0};for(constauto&num:scores){total+=num;}returntotal;}};
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Classes and Objects
You are viewing a single comment's thread. Return to all comments →
Mine wors in my compiler, but when I put the exact same code in the Hackerank compiler, it gives me the wrong answer. Very bizarre: