一、命名空间
 所谓命名空间(namespace),是指标识符的各种可见范围。C++标准程序库中的所有标识符都被定义于一个名为std的命名空间(namespace)中.而我们要使用的string类也是一样的。

要使用它可以有2种方式
(1)
using namespace std
string 标识符;
(2)
std::string 标识符;

二、认识string类
string s1("abddd"); //string s1="abddd";

三、 C++标准输出流cout
 string s1("abddd");
    string s2;
    int i=3;
    //printf("%s\n",s1.data()); //char *
    cout<<s1<<endl<<i<<endl<<s1.length();

 

#include "stdafx.h"
#include <string>
#include <iostream>
using  namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    string s1("abddd");
    string s2;
    int i=3;
    //printf("%s\n",s1.data()); //char *
    cout<<s1<<endl<<i<<endl<<s1.length();
     
    getchar();
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-14
  • 2022-12-23
  • 2021-08-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2021-12-27
  • 2022-01-05
  • 2022-12-23
相关资源
相似解决方案