我试图打印const的值,但它不起作用.我多年后回到C++,所以我知道转换是一种可能的解决方案,但我也无法做到这一点.
代码如下:
//the number of blanks surrounding the greeting
const int pad = 0;
//the number of rows and columns to write
const int rows = pad * 2 + 3;
const string::size_type cols = greeting.size() + pad * 2 + 2;
cout << endl << "Rows : " + rows;
Run Code Online (Sandbox Code Playgroud)
我试图打印'行'的值而没有成功.
小智 6
你要:
cout << endl << "Rows : " << rows;
Run Code Online (Sandbox Code Playgroud)
注意这与此无关const- C++不允许您与+运算符连接字符串和数字.你实际在做的是那种神秘的东西叫做指针算法.