Category : c++14

#include <vector> using std::cin; using std::cout; using std::max; using std::vector; int compute_min_refills(int dist, int tank, vector<int> &stops) { int current_refill, total_refills = 0; stops.push_back(dist); stops.insert(stops.begin(), 0); while (current_refill <= stops.size()) { int last_refill = current_refill; while (current_refill <= stops.size() && stops[current_refill + 1] – stops[last_refill] <= tank) { current_refill++; //std::cout << stops[current_refill + 1] << ..

Read more

I have the following line of code: printf("nnTime taken for simulation: %ld millisecondsn", duration.count() ); On my home machine, I get the error, main.cpp:292:65: error: format specifies type ‘long’ but the argument has type ‘std::__1::chrono::duration<long long, std::__1::ratio<1, 1000>>::rep’ (aka ‘long long’) [-Werror,-Wformat] This error is sorted out if I change %ld to %lld I use ..

Read more

The ROS2 Nodes becomes unresponsive on doing ros2 run. OS: Windows 10 Compiler : Visual Studio 2019 ROS2 Version: Foxy Fixtroy The Visual Studio terminal used for running the node also becomes unresponsive to Ctrl + C This happens with ros nodes which have initialization requirement. Normal ros2 executables without ros2 initialization doesnt get frozen. ..

Read more

Can anyone explain the working of this function? string rightTrim(const string &str) { string s(str); s.erase(find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(), s.end()); return s; } I don’t know the working of not1() and ptr_fun(). Can anyone provide me with a good explanation for this code? PS: I know, thick code removes any white spaces from the end ..

Read more

I was compiling bits/stdc++.h header included with mingw-w64 in using g++ -std=c++17 stdc++.h I got a list of errors ending with C:/MinGW/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:167:5: note: no known conversion for argument 1 from ‘std::basic_string_view<wchar_t>’ to ‘std::filesystem::__cxx11::path&&’ C:/MinGW/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:165:5: note: candidate: ‘std::filesystem::__cxx11::path::path(const std::filesystem::__cxx11::path&)’ path(const path& __p) = default; ^~~~ C:/MinGW/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:165:5: note: no known conversion for argument 1 from ‘std::basic_string_view<wchar_t>’ to ..

Read more

I know there is few questions with a similar title, however I went over them and still couldn’t solve my error. This is the BST implementation: struct node { int val; node* left; node* right; }; node* createNewNode(int x) { node* nn = new node; nn->val = x; nn->left = nullptr; nn->right = nullptr; return ..

Read more