关于C++ string类的小问题 #include iostream#include stringusing namespace std;void main(){ string a="我很好";}如果我couta;那么会输入 我很好 但我只想输出我或者好该怎么做呢?相比char字符串可以直接用[]下标运算付找到并输出很好方便,但a是string是一个对象不能用下标运算符像char一样一定要用string而不是 char
关于C++ string类的小问题
#include <iostream>#include <string>using namespace std;void main(){ string a="我很好";}如果我cout<<a;那么会输入 我很好 但我只想输出我或者好该怎么做呢?相比char字符串可以直接用[]下标运算付找到并输出很好方便,但a是string是一个对象不能用下标运算符像char一样一定要用string而不是 char
相关考题:
阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写对应栏内。【说明】下面的程序实现了类String的构造函数、析构函数和赋值函数。已知类String的原型为:class String{public:String(coust char * str = NULL); //普通构造函数String( const String other); //拷贝构造函数~String(void); //析构函数String perate =(const String other); //赋值函数private:char * m_data; // 用于保存字符串};//String 的析构函数String:: ~String (void){(1);}//String 的普通构造函数String: :String( const char * str){if (2){m_data = new char[1];*m_data = '\0';}else{int length = strlen(str);m_data = new ehar[ length + 1 ];strepy(m_data, str);}}//拷贝的构造函数String:: String( const String other){ int length = strlen(other. m_data);m_data = new char[ length + 1 ];strepy(m_data, other, m_data); //赋值函数String String::operate = (eonst String other) //{if (3)return * this;delete [] m_clara; //释放原有的内存资源int length = strlen( other, m_data);m_data = new chart length + 1 ];(4);return (5);}
下列关于C++预定义流对象的叙述中,正确的是A.cin是C++预定义的标准输入流对象B.cin是C++预定义的标准输入流类C.cout是C++预定义的标准输入流对象D.cout是C++预定义的标准输入流类
下列关于C++预定义流对象的叙述中,正确的是( )。A.Cin是C++预定义的标准输入流对象B.Cin是C++预定义的标准输入流类C.Cout是C++预定义的标准输入流对象D.Cout是C++预定义的标准输入流类
在C++中不仅可以用string定义字符串变量,也可以用string定义字符串数组