C++中const char[] 为什么不能用strlen()?
迷茫
迷茫 2017-04-17 15:07:58
0
3
990

如题所示,为什么字符串加了const就会报错,去掉const就能过?

#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main()
{
    const char letter[] = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";

    cout<<strlen(letter)<<endl;

    return 0;
}
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
左手右手慢动作

Post the error message and take a look. It is normal to execute the following command under Mac and Centos after compilation

g++ test.cpp -o test
./test
阿神

What compiler are you using? GCC 6.2 works fine.

迷茫

Thank you everyone, I made a mistake in the main function. I created two new main functions in a project, which caused this error. Thank you very much

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template