Creation and use of strings in C++<\/span><\/p>\n C++ provides following two types of string representations:<\/p>\n The C-style character string.<\/p>\n<\/li>\n The string class type introduced with Standard C++.<\/p>\n<\/li>\n<\/ul>\n The standard C++ library provides a\u00a0string<\/strong>\u00a0class type that supports all the operations mentioned above, additionally much more functionality. We will study this class in C++ Standard Library but for now let us check following example:<\/p>\n At this point, you may not understand this example because so far we have not discussed Classes and Objects. So can have a look and proceed until you have understanding on Object Oriented Concepts.<\/p>\n When the above code is compiled and executed, it produces result something as follows:<\/p>\n Credits:<\/span><\/p>\n <\/a>http:\/ #TC<\/a>1017 #Mastery<\/a>25<\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":" Creation and use of strings in C++<\/span><\/p>\n C++ provides following two types of string representations:<\/p>\n The C-style character string.<\/p>\n<\/li>\n The string class type introduced with Standard C++.<\/p>\n<\/li>\n<\/ul>\n The standard C++ library provides a string<\/strong> class type that supports all the operations mentioned above, additionally much more functionality. We will study this class in C++ Standard Library but for now let us check following example:<\/p>\n At this point, you may not understand this example because so far we have not discussed Classes and Objects. So can have a look and proceed until you have understanding on Object Oriented Concepts.<\/p>\n When the above code is compiled and executed, it produces result something as follows:<\/p>\n Credits:<\/span><\/p>\n <\/a>http:\/\/www.tutorialspoint.com\/cplusplus\/cpp_strings.htm<\/a><\/span><\/p>\n\n
The String Class in C++:<\/h2>\n
#d6d6d6;\">#include<\/a><\/span>
#d6d6d6;\">str3 <\/span>:<\/span> Hello<\/span>\nstr1 <\/span>+<\/span> str2 <\/span>:<\/span> HelloWorld<\/span>\nstr3<\/span>.<\/span>size<\/span>()<\/span> :<\/span> 10<\/span><\/pre>\n
\n
The String Class in C++:<\/h2>\n
#d6d6d6;\">#include<\/a><\/span> <\/span>\n#include<\/a><\/span> <\/span>\n\nusing<\/span> namespace<\/span> std<\/span>;<\/span>\n\nint<\/span> main <\/span>()<\/span>\n{<\/span>\n string<\/span> str1 <\/span>=<\/span> \"Hello\"<\/span>;<\/span>\n string<\/span> str2 <\/span>=<\/span> \"World\"<\/span>;<\/span>\n string<\/span> str3<\/span>;<\/span>\n int<\/span> len <\/span>;<\/span>\n\n \/\/ copy str1 into str3<\/span>\n str3 <\/span>=<\/span> str1<\/span>;<\/span>\n cout <\/span> \"str3 : \"<\/span> str3 <\/span> endl<\/span>;<\/span>\n\n \/\/ concatenates str1 and str2<\/span>\n str3 <\/span>=<\/span> str1 <\/span>+<\/span> str2<\/span>;<\/span>\n cout <\/span> \"str1 + str2 : \"<\/span> str3 <\/span> endl<\/span>;<\/span>\n\n \/\/ total lenghth of str3 after concatenation<\/span>\n len <\/span>=<\/span> str3<\/span>.<\/span>size<\/span>();<\/span>\n cout <\/span> \"str3.size() : \"<\/span> len <\/span> endl<\/span>;<\/span>\n\n return<\/span> 0<\/span>;<\/span>\n}<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre>\n
#d6d6d6;\">str3 <\/span>:<\/span> Hello<\/span>\nstr1 <\/span>+<\/span> str2 <\/span>:<\/span> HelloWorld<\/span>\nstr3<\/span>.<\/span>size<\/span>()<\/span> :<\/span> 10<\/span><\/pre>\n