所以我正在玩一些数组,我无法弄清楚为什么这不起作用.
int numbers[5] = {1, 2, 3};
int values[5] = {0, 0, 0, 0, 0};
values = numbers;
Run Code Online (Sandbox Code Playgroud)
出现以下错误:
Error 1 error C2106: '=' : left operand must be l-value c:\users\abc\documents\visual studio 2012\projects\consoleapplication7\consoleapplication7\main.cpp 9 1 ConsoleApplication7
Run Code Online (Sandbox Code Playgroud)
为什么我不能这样做?错误是什么意思?
当我运行示例代码时,wordLength为7(因此输出7).但是我的char数组最终得到了一些非常奇怪的字符.
wordLength = word.length();
cout << wordLength;
char * wordchar = new char[wordLength]; //new char[7]; ??
for (int i = 0; i < word.length(); i++) //0-6 = 7
{
wordchar[i] = 'a';
}
cout << wordchar;
Run Code Online (Sandbox Code Playgroud)
输出:7aaaaaaa²²²²||||||||||||||||||||||||||||||||||
期望的输出是:aaaaaaa ......背后的垃圾是什么?那是怎么结束的呢?