[Solved] Removing punctuation from string of characters [closed]

Take a look at remove_if() #include <iostream> #include <algorithm> #include <string> using namespace std; int main() { string s; getline(std::cin,s); cout << s << endl; s.erase (std::remove_if(s.begin (), s.end (), ispunct), s.end ()); cout << s << endl; } 4 solved Removing punctuation from string of characters [closed]

[Solved] taking specific time then output result?

C++11 solution #include <iostream> #include <chrono> #include <thread> int main() { using namespace std::literals; std::this_thread::sleep_for(5s); std::cout << “Hello world” << std::endl; } Read more http://en.cppreference.com/w/cpp/thread/sleep_for solved taking specific time then output result?

[Solved] Printing contents of a vector [duplicate]

As you mentioned “I did not understand what the code is doing”, let me briefly describe how to iterate through a container: The long way: vector<int> result = { 1,2,3 }; for (vector<int>::iterator it = result.begin(); it != result.end() ; it++) { int i = *it; cout << i << ” “; } Each container … Read more

[Solved] Can’t seems to inherit a protected variable

Yes, a B can access protected members of an A. But it’s the fact that you’re going through v3 that makes it essentially irrelevant that this attempt is made from within a member function of B. It’s v3 trying to make the access, not B::calculate, and v3 is not a B&. [C++11: 11.4/1]: [..] All … Read more

[Solved] C++: What is best way to destruct this code? [closed]

C++: What is best way to destruct this code? You mean to free resources. In case of unordered_map The way to do it right is not to do it. A unordered_map will automatically release resources when it’s destroyed for anything allocated automatically. Unless you allocated the values with new, you don’t delete them. In case … Read more

[Solved] How to write one line and nested ‘if’ statement without ‘?:’ (is it possible?)

You already used the two important words that are key to undestand why what you intend is not possible, but you probably haven’t grasped their full meaning: Statement and expression. The if statement (like all statements) does not yield a value, while the ?: operator is an expression that does yield a value. Distinguishing between … Read more

[Solved] Making a new function by fixing one of the input parameters [closed]

You probably want lambda or std::function, or std::bind auto l_add_100 = [](double x) { return add_two_numbers(x, 100); }; std::function<double(double)> f_add_100 = [](double x) { return add_two_numbers(x, 100); } auto b_add_100 = std::bind(add_two_numbers, std::place_holder::_1, 100); or with non hard coded number double y = //… auto l_add_y = [y](double x) { return add_two_numbers(x, y); } std::function<double(double)> … Read more

[Solved] C++ Need help for a homework program that reads in a list of doubles from a file and add a string to each double

Call bubbleSort(rain, MAX_MONTHS); in main with these changes : void displayRainfall(string months[MAX_MONTHS], double rain[MAX_MONTHS], int monthCount) { //title cout << “Monthly Rainfall for 2014” << endl; //print minimum rainfall cout << “Minimum: ” << months[MAX_MONTHS-1] << ” “<< rain[MAX_MONTHS-1] << endl; //print maximum rainfall cout << “Maximum: ” << months[0] << ” “<< rain[0] << … Read more

[Solved] What does the namespace std add? (C++) [closed]

1 – All the entities (variables, types, constants, and functions) of the standard C++ library are declared within the std namespace. using namespace std; introduces direct visibility of all the names of the std namespace into the code. ref: http://www.cplusplus.com/doc/tutorial/namespaces/ 2 – Namespaces in C++ are most often used to avoid naming collisions. Although namespaces … Read more