目录
定义自己的命名空间myspace,并在myspace中定义一个字符串,实现求字符串大小的函数。
思维导图
定义自己的命名空间myspace,并在myspace中定义一个字符串,实现求字符串大小的函数。
#include <iostream>
#include <string>
using namespace std;
namespace myspace
{
string str ="hello";
int length_str(string str)
{
int count=0;
while (str[count]!='\0') {
count++;
}
return count;
}
}
using namespace myspace;
int main()
{
string s;
getline(cin,s);
cout << "length=" << myspace::length_str(s) << endl;
return 0;
}