Syntax

C++ Use std::string Syntax

In C++, use std::string: works with text strings — std::string s = "hi"; s += "!"; s.size();

Quick Answer

Syntax
std::string s = "hi"; s += "!"; s.size();
C++Syntax

Use std::string

Code example
std::string s = "hi"; s += "!"; s.size();

Works with text strings.

Learn More

How to use std::string in C++

  1. Open your C++ file or editor.
  2. Copy the example, then replace its sample names and values for your code.

C++ Use std::string Syntax

Use std::string s = "hi"; s += "!"; s.size();.

Related Syntax References

Frequently asked questions

What is the C++ syntax for use std::string?

Use this pattern: std::string s = "hi"; s += "!"; s.size();

Can I copy this C++ code example?

Yes. Use Copy code and adapt the example to your program.

Is this C++ syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify