⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 414.cpp

📁 C++实训教程
💻 CPP
字号:
//414.CPP  创建对象的方法:全局对象、静态对象、使用引用、使用指针和局部对象
#include <iostream.h>
#include <cstring.h>

string sg("Global.");// a global string
void main()
{
  string& s1=*(new string("using reference")); //using reference
  string* pS2=new string ("using pointer");    //using pointer
  static string ss("Static.");
  string& s5=*(new string(s1));                //reference,new,copy

  cout <<"Display a global string    = " << sg << endl;
  cout <<"Display a string 1(&)      = " << s1 << endl;
  cout <<"Display a string 2(*)      = " <<*pS2<< endl;
  cout <<"Display a string 5(copy s4)= " << s5 << endl;
  cout <<"Display a static string    = " << ss << endl;
  s5 = "A new fifth string";
  cout <<"Display a new string 5 =     " << s5 << endl;
  delete &s1;
  delete pS2;
  delete &s5;
}
/*
Display a global string    = Global.
Display a string 1(&)      = using reference
Display a string 2(*)      = using pointer
Display a string 5(copy s4)= using reference
Display a static string    = Static.
Display a new string 5 =     A new fifth string

*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -