This code declares a string variable word and initializes it with the value "Ram". It then modifies the first character of the string to 'S' using the subscript operator, and prints the modified string to the console using cout.
Note that in C++, strings are objects, and you can access and modify individual characters in the string using the subscript operator []. However, modifying a character in a string literal (like "Ram") is not allowed and can result in undefined behavior. It's safer to declare the string as a non-constant variable before modifying it.
Also note that the string.h library is not necessary for this code and can be removed. The string class is included in the standard C++ library and can be used directly.
#include<iostream> #include<string.h> using namespace std; int main() { string word="Ram"; word[0]='S'; cout<<"\n"<<word; return 0; }To download raw file Click Here
Sam
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions