Get the App
SLTechnology News&Howtos  ›  Development  › 

How do C++ number types and string types convert each other

Shulou Source: shulou.com Published: 2022-06-03 19:10:16 11月12日 Update

This article introduces the knowledge of "how to convert C++ number types and string types". Many people will encounter this dilemma in the operation of actual cases. then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Catalogue

Convert a first-level directory number into a string

Convert a secondary directory string to a number

First-level directory number to string, second-level directory string to number.

1. Convert a number to a string

(1)。 First of all, add the header file.

# include

< iostream >

# include

< sstream >

# include

< string >

This class is defined in the header file

< sstream>

The library defines three categories: istringstream, ostringstream, and stringstream, which are used for stream input, output, and input / output operations, respectively. In addition, each class has a corresponding version of a wide character set.

To achieve this goal, it must be the stringstream class.

Int iDefinitions 100.22; / / defines a variable str; stringstream s; s with stringstream

Tags: Characters numbers strings output directories types singles files inputs caches contents functions integers more knowledge practicality learning and then no that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Linux Microsoft OPPO Reno Shulou Tech Info