简体   繁体   English

IntelliSense:不存在从“ std :: string”到“ char”的合适转换函数,那么我该如何处理?

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

相关问题 如何摆脱“智能感知:没有合适的转换函数从”std :: string“到”std :: string *“存在”错误? - How do I get rid of the “Intellisense: no suitable conversion function from ”std::string“ to ”std::string *“ exists” error? 6 IntelliSense:不存在从“ std :: string”到“ int”的合适转换函数 - 6 IntelliSense: no suitable conversion function from “std::string” to “int” exists 不存在从标准字符串到const char *的合适转换函数 - No suitable conversion function from std string to const char * exists 不存在从“std::string”到“const char *”的合适转换函数 - No suitable conversion function from “std::string” to “const char *” exists 不存在从“ std :: string”到“ char”的适当转换 - no suitable conversion from “std::string” to “char” exists 如何修复“没有合适的转换函数从”String“到”const char *“存在”? - How to fix “no suitable conversion function from ”String“ to ”const char *“ exists”? 我收到错误消息:std :: basic_istream没有合适的转换函数 <char, std::char_traits<char> &gt;到char存在 - I'm getting the error: no suitable conversion function from std::basic_istream<char, std::char_traits<char>> to char exists c++ 不存在从“std::string”到“const char*”的合适转换函数 - c++ no suitable conversion function from "std::string" to "const char*" exists 1 IntelliSense:没有合适的构造函数可以从“bool”转换为“std :: basic_string” <char, std::char_traits<char> ,std :: allocator <char> &gt;” - 1 IntelliSense: no suitable constructor exists to convert from “bool” to “std::basic_string<char, std::char_traits<char>, std::allocator<char>>” 从“ std :: string”到“ PVOID”的转换功能不存在 - no suitable conversion function from “std::string” to “PVOID” exists
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM