- C++ Game Development By Example
- Siddharth Shekar
- 182字
- 2021-06-24 14:26:10
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:

- Android NDK Game Development Cookbook
- 計算機組裝與系統配置
- 計算機組裝·維護與故障排除
- 單片機原理及應用系統設計
- 從零開始學51單片機C語言
- Camtasia Studio 8:Advanced Editing and Publishing Techniques
- 電腦軟硬件維修從入門到精通
- R Deep Learning Essentials
- 深入理解序列化與反序列化
- VMware Workstation:No Experience Necessary
- Istio服務網格技術解析與實踐
- Spring Cloud微服務和分布式系統實踐
- Blender 3D By Example
- 微控制器的應用
- Zabbix 4 Network Monitoring