[英]IntelliSense: no suitable conversion function from “std::string” to “char” exists so how do i go about this?
the char letters[] = {value}; 字符char [[] = {value}; part is where i am getting the problem 部分是我遇到问题的地方
static string Cipher(string value, int offset)
{
char letters[] = {value};
char DifferentLetters[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','u','r','s','t','v','w','x','y','z'};
for (int i = 0; i < DifferentLetters[i]; i++)
{
char letter = DifferentLetters[i];
int defaultOffset = offset;
if(letter > 'z')
{
letter = (char)(letter - defaultOffset);
}
else if(letter < 'a')
Setting aside the more basic question of why you would want to do such a thing, the equivalent to what you expect 撇开一个更基本的问题,即为什么要做这样的事情,这相当于您的期望
char letters[] = {value};
to mean would be 意思是
char letters[value.size()+1];
memcpy(letters,value.c_str(),value.size()+1);
Of course, that assumes a newer version of C++ that allows run time sizing of local C arrays (I forget which version that was added in, but certainly not very early versions). 当然,这假定使用的新版本的C ++允许在运行时调整本地C数组的大小(我忘记添加了哪个版本,但肯定不是很早的版本)。 Also you need to include something like string.h to get the declaraction of memcpy. 另外,您还需要包括string.h之类的内容,以获取memcpy的声明。
The following might be a cleaner alternative, but it is further from the original meaning in ways that may cause it to be unacceptable (depending on subsequent use of letters and value): 以下内容可能是更干净的替代方法,但与原始含义有所不同,可能会导致其无法接受(取决于随后使用的字母和值):
char* letters = value.c_str();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.