简体   繁体   English

参数类型为:(size_t,const char [2])

[英]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.

相关问题 错误:无法将参数1的const字符串转换为const char *到size_t strlen(const char *) - error: cannot convert const string to const char* for argument 1 to size_t strlen(const char*) 字符串(const char *,size_t)转换为int吗? - String (const char*, size_t) to int? 在 &quot;&quot; 运算符中从字符串转换为 const char* + size_t - Conversion from string to const char* + size_t in ""operator 为什么字符串(const char * s,size_t pos,size_t len = npos)有效? - Why does string (const char* s, size_t pos, size_t len = npos) work? 错误C2664:&#39;errno_t wcstombs_s(size_t *,char *,size_t,const wchar_t *,size_t)&#39;:无法转换参数4 - error C2664: 'errno_t wcstombs_s(size_t *,char *,size_t,const wchar_t *,size_t)' : cannot convert parameter 4 无法将参数 &#39;1&#39; 的 &#39;std::string&#39; 转换为 &#39;char**&#39; 到 &#39;__ssize_t getline(char**, size_t*, FILE*)&#39; - cannot convert ‘std::string’ to ‘char**’ for argument ‘1’ to ‘__ssize_t getline(char**, size_t*, FILE*)’ 我们会在未来的 C++ 版本中使用 size_t strlen(const char8_t*) - Will we have a size_t strlen(const char8_t*) in a future C++ version 为什么不强制 operator new 将参数作为“const size_t”? - Why isn't operator new forced to take argument as “const size_t”? 常量size_t在mex中的转换 - Conversion of const size_t in mex 将size_t转换为vector <unsigned char> - Convert size_t to vector<unsigned char>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM