0

If I don't want to use namespace and use <cstdlib> for std :: cout, it gives an error "string does not name type".

Should I add any other library? https://code.sololearn.com/c01RH8Khw74C/?ref=app

17th Jan 2020, 7:09 AM
Master Forts 🇦🇷
Master Forts 🇦🇷 - avatar
6 Respostas
+ 4
Master Forts This way you can do so change string to std::string variable_name; std::endl; https://code.sololearn.com/cLNAxGo65i33/?ref=app
17th Jan 2020, 8:06 AM
DishaAhuja
DishaAhuja - avatar
+ 4
Alright, Thanks for elaborating, now I understand this better. Well, for one thing, I can assure you that you may not need to include <cstdlib> just because you don't use "using namespace std;". You only need <cstdlib> if your code uses one of the functions, constants etc. that is defined in <cstdlib>. For everything defined in standard namespace (std), you will have to write the syntax in full form. That means you prefix the syntax with 'std::' such as (but not limited to): std::cin instead of just cin std::cout instead of just cout std::endl instead of just endl std::string instead of just string Or alternatively, as you have learned ... using std::cin; using std::cout; using std::endl; using std::string; Less hassle this way ...
17th Jan 2020, 8:21 AM
Ipang
+ 1
Thanks for your interest. I want that same code without using namespace std; In C ++ the namespace is seen as bad programming because finding an error would be difficult. So if I remove it in the code, I must add the <cstdlib> library and declare: using std :: cout; using std :: cin; using std :: endl; But in doing so, having a copy constructor, on line 13, the word string fails when I declare the copy of the data constant. For that same code to work without namespace, what modifications should I make?
17th Jan 2020, 8:00 AM
Master Forts 🇦🇷
Master Forts 🇦🇷 - avatar
+ 1
brilliant thank you very much
17th Jan 2020, 8:13 AM
Master Forts 🇦🇷
Master Forts 🇦🇷 - avatar
+ 1
Very grateful, timely explanation as I try to understand that syntax. 
17th Jan 2020, 8:28 AM
Master Forts 🇦🇷
Master Forts 🇦🇷 - avatar
0
Can you please edit your question? I am not understanding your question. The code runs with no problem, BTW.
17th Jan 2020, 7:49 AM
Ipang