
定义自己的命名空间myspace,并在myspace中定义一个字符串,实现求字符串大小的函数。
#include <iostream>
using namespace std;
namespace zzw {
static string str="hello world";
}
int size_str()
{
string str1=zzw::str;
return str1.size();
}
int main()
{
int size = size_str();
cout << "字符串长度是:" << size << endl;
return 0;
}
本文介绍了如何在C++中定义一个命名空间myspace,并在其中存储字符串,然后实现一个函数size_str()来计算字符串的长度,展示了在主函数main中调用该函数的示例。
264

被折叠的 条评论
为什么被折叠?



