相关疑难解决方法(0)

"&s [0]"是否指向std :: string中的连续字符?

我正在做一些维护工作,遇到类似以下的事情:

std::string s;
s.resize( strLength );  
// strLength is a size_t with the length of a C string in it. 

memcpy( &s[0], str, strLength );
Run Code Online (Sandbox Code Playgroud)

我知道使用&s [0]如果它是std :: vector会是安全的,但是这是std :: string的安全使用吗?

c++ stdstring memcpy c++03

37
推荐指数
3
解决办法
1万
查看次数

为什么不能使用“=”运算符将一个数组变量直接分配给另一个数组变量?

为什么以下作业不起作用?如果可能的话,我想要一个低级的解释。另外,这是我得到的编译器错误:'char*' 到 'char [20]' 赋值中的类型不兼容

class UCSDStudent {

  char name[20];

  public:

    UCSDStudent( char name[] ) {
      //this-> name = name; does not work! Please explain why not
      strcopy( this -> copy, copy ); //works 
    }

};
Run Code Online (Sandbox Code Playgroud)

c++ arrays char-pointer

5
推荐指数
1
解决办法
7394
查看次数

标签 统计

c++ ×2

arrays ×1

c++03 ×1

char-pointer ×1

memcpy ×1

stdstring ×1