+ 2

C++ calculator

I'm tryin to make a cpp calculator but idk how do I make the user to input a int instead of str. basiclly when someone inputs a string I want it to print ,,That isn't a number" How do I do that?

6th Apr 2018, 5:01 AM
sovietcat
sovietcat - avatar
8 Respostas
+ 3
int input; if (!(std::cin >> input)) std::cerr << "Your input could not be validated, did you provide something else than a number?\n";
6th Apr 2018, 7:14 AM
Timon Paßlick
+ 1
It's if you don't want to use the std namespace: https://youtu.be/4NYC-VU-svE
6th Apr 2018, 7:25 AM
Timon Paßlick
+ 1
Yes, it groups classes, functions and globals, mainly to avoid name conflicts between libraries.
6th Apr 2018, 7:32 AM
Timon Paßlick
+ 1
namespace example { class Something {…}; void foo(){…}; } int main() { example::foo(); } //or using namespace example; int main() { foo(); }
6th Apr 2018, 8:33 AM
Timon Paßlick
0
Oh but what does ,,std" and ,,::" do? Also why is there ,,!" in the parenthases?
6th Apr 2018, 7:24 AM
sovietcat
sovietcat - avatar
0
I'm new so I don't really understand what std and namespace is. Is namespace like a library similar like you ,,import (Library name)" in Python 3?
6th Apr 2018, 7:27 AM
sovietcat
sovietcat - avatar
0
oh god I still don't get it lol
6th Apr 2018, 8:10 AM
sovietcat
sovietcat - avatar
16th Nov 2020, 3:42 PM
Anas kayani
Anas kayani - avatar