- 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:

- Learning SQL Server Reporting Services 2012
- Istio入門與實戰
- 電腦維護與故障排除傻瓜書(Windows 10適用)
- 計算機應用與維護基礎教程
- 平衡掌控者:游戲數值經濟設計
- 微服務分布式架構基礎與實戰:基于Spring Boot + Spring Cloud
- Spring Cloud微服務架構實戰
- 固態存儲:原理、架構與數據安全
- 深入理解序列化與反序列化
- 基于PROTEUS的電路設計、仿真與制板
- Hands-On Deep Learning for Images with TensorFlow
- STM32自學筆記
- IP網絡視頻傳輸:技術、標準和應用
- Intel FPGA權威設計指南:基于Quartus Prime Pro 19集成開發環境
- 單片機項目設計教程