I just started learning c++ and got an error while doing practicing. I was practicing using namespace and cin, cout.
I tried to print out the function of each namespace by each input. Here below is the code I wrote :
#include "iostream" using namespace std; namespace ns1 { int pp() { int x = 1; for (int i = 0; i < 9; i++) { cout << x << endl; x++; } return 0; } } namespace ns2 { void pp() { double x = 2; while (x < 6) { cout << x << endl; x += 1.7; } } } int main() { bool check = 0; cout << "Type 0 or 1 then you will have the following answer" << endl; cin >> check; if (check == 0) { cout << ns1::pp() << endl; } else { cout << ns2::pp() << endl; } return 0; } I don't know why void pp() cannot be printed out.
Could anyone let me know why it happens?
void. Silly library...voidreturns nothing. As such there is nothing to print.cout << ns2::pp() << endl;supposed to print?