官术网_书友最值得收藏!

Strings

Variables that are non-numerical are either a single character or a series of characters called strings. In C++, a series of characters can be stored in a special variable called a string. A string is provided through a standard string class.

To declare and use string objects we have to include the string header file. After #include <conio.h>, also add #include <string> at the top of the file.

A string variable is declared in the same way as other variable types, except before the string type you have to use the std namespace.

If you don't like adding the std:: namespace prefix, you can also add the line using the std namespace. After the #include. This way, you won't have to add the std:: prefix, as the program will understand. However, it can be printed out just like other variables:

#include <iostream> 
#include <conio.h> 
#include <string> 
 
// Program prints out values to screen 
 
int main() 
{ 
 
   std::string name = "The Dude"; 
 
   std::cout << "My name is: " << name << std::endl; 
 
   _getch(); 
   return 0; 
} 

Here is the output:

主站蜘蛛池模板: 铅山县| 天峻县| 平江县| 社会| 察隅县| 潼关县| 阳谷县| 青阳县| 静海县| 甘肃省| 罗田县| 玉林市| 阿拉善右旗| 临邑县| 昭平县| 南和县| 黑山县| 北海市| 安新县| 武城县| 剑川县| 军事| 任丘市| 亳州市| 色达县| 临海市| 赤水市| 秦皇岛市| 邵阳县| 永新县| 荔波县| 于田县| 北宁市| 游戏| 锡林郭勒盟| 扶余县| 彭阳县| 西青区| 岗巴县| 双桥区| 崇左市|