声明一个固定大小的字符串 [英] Declaring a string of fixed size
本文介绍了声明一个固定大小的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C语言中我们
char buffer[100];
有没有一种方法可以声明固定大小的 std :: string
?
Is there a way to declare a fixed size std::string
?
推荐答案
您可以使用 string :: reserve 方法
std::string s;
s.reserve(100);
但这不是固定大小,因为您可以使用string ::向字符串添加更多字符::例如push_back。
But this isn't fixed size, because you can add more chars to the string with string::push_back for example.
这篇关于声明一个固定大小的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文