Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1231  / 1 Year ago, sun, march 19, 2023, 4:36:45
#include<iostream>
int main()
{
char ch = 'A';
int num = ch;

cout << "The ASCII code for " << ch << "is " << num << "
";
cout << "Adding 1 to the character code :
";
ch = ch + 1;
num = ch ;
cout << "The ASCII code for " << ch << "is " << num << "
";
return (0);
}


I get the errors like



ex1.cpp: In function ‘int main()’:
ex1.cpp:6:5: error: ‘cout’ was not declared in this scope
ex1.cpp:6:5: note: suggested alternative:
/usr/include/c++/4.6/iostream:62:18: note: ‘std::cout’


Guys please correct my mistakes.


More From » 12.04

 Answers
6

Do not add a global using namespace std as other users are saying, this is an extremely bad practice, learn how to use methods and namespaces instead.



cout is not a particular method, std::cout is the method cout from the std namespace and this is the correct way to write methods in C++.


[#32287] Tuesday, March 21, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
poefor

Total Points: 379
Total Questions: 95
Total Answers: 115

Location: Serbia
Member since Tue, Jul 26, 2022
2 Years ago
;