![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I define string constants in C++?
To define a string constant in C++, you have to include the string header library, then create the string constant using this class and the const keyword.
Example
#include<iostream> #include<string> int main() { const std::string MY_STRING = "Hello World!"; std::cout << MY_STRING; return 0; }
Output
This will give the output −
Hello World!
Note that if you try to reassign a value to this variable it'll cause an error.
Advertisements