簡體   English   中英

錯誤:無法轉換 &#39;std::basic_string<char> &#39; 到 &#39;char&#39; 賦值

[英]error: cannot convert 'std::basic_string<char>' to 'char' in assignment

當我編譯這段代碼時,我總是收到這個錯誤。 這里 dna 設置為 char。 我希望將 bitset 中的位值轉換為 char,將 char 轉換為 int。 如果這不是正確的方法,請指導。

for (std::size_t i = 0; i < myString.size(); ++i)  
{
    std::bitset<8> y(myString[i]);

    dna = y.to_string<char>();
    binary = dna;
    cout << binary << " ";
    while ( binary >= 10) {
        for(int i = 0; i <= 100; ++i) { // loops length of array
            a[i] = binary % 10;
            binary = binary / 10;
        }
    }
}

y.to_string(); 返回std::string 它不能轉換為char

用這個:

std::string dna = y.to_string();
unsigned long binary = y.to_ulong();

人,請不要投票我的帖子。 我需要它作為“頑強”徽章。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM