- 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
- SDL Game Development
- INSTANT Wijmo Widgets How-to
- The Applied AI and Natural Language Processing Workshop
- Artificial Intelligence Business:How you can profit from AI
- Camtasia Studio 8:Advanced Editing and Publishing Techniques
- 筆記本電腦維修不是事兒(第2版)
- 微服務(wù)分布式架構(gòu)基礎(chǔ)與實(shí)戰(zhàn):基于Spring Boot + Spring Cloud
- 單片機(jī)系統(tǒng)設(shè)計(jì)與開發(fā)教程
- 單片機(jī)技術(shù)及應(yīng)用
- Mastering Machine Learning on AWS
- 單片機(jī)原理與技能訓(xùn)練
- 觸摸屏應(yīng)用技術(shù)從入門到精通
- Mastering Quantum Computing with IBM QX
- 微服務(wù)實(shí)戰(zhàn)