[英]argument types are:(size_t, const char[2])
//build a greeting const string greeting = "Hello, " + name + "!"; //建立一个问候语常量字符串greeting =“ Hello,” + name +“!”; <-- nsme is a string entered in cmd line
<-nsme是在cmd行中输入的字符串
//build 2nd and fourth lines of the output
const string spaces(greeting.size()," "); <-- getting red line here
const string second = "* " + spaces + " *";
//build the first and fifth lines
const string first(second.size(), "*"); <-- getting red line here
I understand what the code is trying to do - ie: set the size - but I'm not sure why this isn't working. 我了解代码正在尝试执行的操作-即:设置大小-但我不确定为什么这不起作用。 Intellisense had 'size' in the options list after I hit the '.'
在我点击“。”后,Intellisense在选项列表中显示了“大小”。 following greeting and second so I expected this to work.
接下来的问候和第二,所以我希望这个工作。 Using VS2013 pro.
使用VS2013专业版。
const string spaces(greeting.size()," ");
std::string
does not have a constructor that can take those arguments. std::string
没有可以接受这些参数的构造函数。
What do you expect it to do? 您期望它做什么? If you want a string with N copies of a single character you need to pass it a single character, not an array of characters ie
如果您想要一个包含N个单个字符副本的字符串,则需要将其传递给单个字符,而不是字符数组,即
const string spaces(greeting.size(), ' ');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.