In: Computer Science
1) As mentioned in this chapter, C++ predefined identifiers such as cout and cin can be redefined by the programmer. However, why is it not wise to do so?
2) The text mentioned that the char data type can be cast into an int. What are some possible uses of this functionality?
3) Introduce the C++ data type string, which is a programmer-defined data type available in the C++ library. Define a string as a sequence of zero or more characters.
Please explain in detail.
1)
Ans:- Of course the classes ostream and istream are user defined but as a user of c++ we can't modify the those classes and they are not built in c++ so modify those function definition is not good idea.
2)
Ans:- To get the equivalent integer we can use ASCII value of that char or you will get the equivalent char of ASCII integer value
for example
#include <iostream>
using namespace std;
int main()
{
char ch = 'A';
int n = (int)ch;
cout<< n<<endl;
cout<<(char)65;
return 0;
}
3)
Ans : -You'll need to include the library of string class #include <string> as the header file, it is type of char * or char[] type
#include<iostream>
#include<string> // for string class
using namespace std;
int main()
{
// Declaring string
string str = "000000000000111AAA";
cout<<str;
return 0;
}
Please let me know if you have any doubt or modify the answer, Thanks :)