Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ fixed length string class?

Tags:

c++

string

Is there anything like this in Standard C++ / STL? Ideally it should be constructed like

fstring s = fstring(10);

I need to sometimes construct or have a string of fixed size. Sometimes to be able to read / write only that many characters into a stream.

Edit:

Note that the size is only known at runtime, and is different from one to the other. But all of the fstrings should know how to work together and have all the fancy string behavior.

like image 351
Ayman Avatar asked Oct 15 '09 11:10

Ayman


1 Answers

With ISO C++ +17 you can do this

#include <string_view>
......
char dataBuffer[BUFF_SIZE];
auto commandString = std::string_view{ dataBuffer };
......
like image 151
Thinkal VB Avatar answered Sep 20 '22 11:09

Thinkal VB