class String
{
private:
static const int SZ = 80;
char str[SZ];
public:
String()
{
strcpy_s(str, " ");
}
String(char s[])
{
strcpy_s(str, s);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我写的构造函数,请注意第二个
在这里我使用它:
String s1 = "yes";
String s2 = "no";
String s3;
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
严重性代码描述项目文件行抑制状态错误(活动)E0415没有合适的构造函数可以从"const char [4]"转换为"String"rishabh c ++项目F:\ rishabh c ++ projects\rishabh c ++ projects\main.cpp 35
// merge.cpp
// merges two containers into a third
#include <iostream>
#include <algorithm> //for merge()
using namespace std;
int src1[] = { 2, 3, 4, 6, 8 };
int src2[] = { 1, 3, 5 };
int dest[8];
int main()
{ //merge src1 and src2 into dest
merge(src1, src1+5, src2, src2+3, dest);
for(int j=0; j<8; j++) //display dest
cout << dest[j] << ' ';
cout << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是我键入的代码和我期望的是一个已排序的合并数组,但输出结果如下:
1210537622105376321053763210537642105376521053766210537682105376
Run Code Online (Sandbox Code Playgroud)
我改变了数据,重新检查了语法,但我觉得每件事都很好