How to get value from a vector by value from another vector?

Advertisements I have two vectors: one contains numbers and names of things; second collects numbers that have already been showed to the user; I’m trying to make a history list of all objects that have been shown. Here is my code: class palettArchive{ private: std::vector<std::pair<int,std::string>> paletts; int palletsCounter; std::vector<int> choosen; public: //… void history(){ auto… Read More How to get value from a vector by value from another vector?

C++ higher order functions: different results when declaring multiple functions

Advertisements I was plying with higher order functions, and I started getting different results when I created two instances and assigning them to variables. I reduced the issue to the following example: #include <iostream> using ColorGetter = int(*)(void); auto paint(const ColorGetter &f) { return [&]() { return f(); }; } int colorA() { return 10;… Read More C++ higher order functions: different results when declaring multiple functions

C++ Can not manage to display the class datatype array

Advertisements This is the code I wrote, total beginner #include <iostream> #include <cstring> using namespace std; class Person { public: string ID; string name; string surname; string department; string email; public: //get and set functions for ID, Name, Surname, Department, Email properties string getID() { return this->ID; }; void setID(string _ID) { this->ID = _ID;… Read More C++ Can not manage to display the class datatype array

Why does operator==(std::variant<T, U>, T) not work?

Advertisements Consider the following: #include <iostream> #include <variant> int main () { std::variant<int, float> foo = 3; if(foo == 3) { std::cout << "Equals 3\n"; } } Godbolt demo here This does not compile because of the foo == 3: <source>:7:12: error: no match for ‘operator==’ (operand types are ‘std::variant<int, float>’ and ‘int’) 7 |… Read More Why does operator==(std::variant<T, U>, T) not work?

What is a call to `char()` as a function in C++?

Advertisements I’ve never seen this call to char() as a function before. Where is this described and what does it mean? This usage is part of the example on this cppreference.com community wiki page: https://en.cppreference.com/w/cpp/string/basic_string/resize: short_string.resize( desired_length + 3 ); std::cout << "6. After: \""; for (char c : short_string) { std::cout << (c ==… Read More What is a call to `char()` as a function in C++?

QProcess: The system cannot find the file specificed even when full path is provided

Advertisements Here is my full code: #include <QCoreApplication> #include "iostream" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QProcess process; QString path = "C:\\Windows\\System32\\wbem\\WMIC.exe"; QString arg = "cpu get name"; QStringList arguments; arguments << arg; //process.start(path,arguments); process.start(path + " " + arg); //qDebug() << "Started"; std::cout << "Started" << std::endl; if (!process.waitForFinished()){ qDebug() <<… Read More QProcess: The system cannot find the file specificed even when full path is provided