Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the string class in the C++STL container

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use the string class in the C++STL container. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Preface

Why learn the string class:

In C language, a string is a collection that ends with'\ 0'. For convenience, some str series functions (strstr,strcmp,strcpy) are provided in the C standard library. However, these library functions are separated from strings, which is not quite in line with the idea of oop A little carelessness can lead to cross-border visits.

In the OJ question, the string question basically appears in the form of string, and in the routine work, in order to be simple, convenient, fast, basically use the string class, few people will use the string operation function in the C library.

1. String classes in the standard library

The 1.string class is the type of character that represents a string.

two。 The interface of this class is basically the same as that of a regular container, adding some general operations specifically used to manipulate string.

The bottom layer of 3.string is the alias of the basic_string template class.

4. Cannot manipulate sequences of multi-byte or variable-length characters.

When using string, the header files # include and using namespace std must be included

The common interface description of 2.string class 2.1Common construction of string object string () Construction empty string class object string (const char* str) Construction of string class string (size_t nmae char ch) string object contains n characters cstring (const string& s) with constant character creation as parameter

Copy constructor

# include#includeusing namespace std;int main () {string S1; string S2 ("CSDN"); string S3 (4,'A'); string S4 (S2); cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report