-1

最初にwhileループ内に書いstd::istringstream iss(std::move(string));たので、ループ内でエラーが発生しましcrosses initializationた。現在、ループ内にはありませんが、それでもエラーが発生しますcrosses the initialization

void *SocketHandler(void *lp)
{
    typedef std::unordered_map<std::string,int> occurrences;
    occurrences s1;
    std::string ss;
    std::ostringstream bfr;
    std::string result_string;
    std::vector<std::string> most;
    int max_count = 0;
    int tmp=0;

    while ((NULL != word) && (50 > i)) {
        ch[i] = strdup(word);
        excluded_string[j]=strdup(word);
        word = strtok(NULL, " ");
        skp = BoyerMoore_skip(ch[i], strlen(ch[i]) );
        bfr << excluded_string[j] << " ";
        result_string = bfr.str();
        j++;
        //  std::cout << "string is :" << r1;
        i++;
        if(str==NULL && str==NULL and skp !=NULL)
        {
            pcount=0;
            ncount=0;
        }
    }
    std::cout << "string is :" << result_string << "\n";
    std::istringstream iss(std::move(result_string));  // **Here it gives error**

    while (iss >> result_string)
    {
        tmp = ++s1[result_string];
        if (tmp == max_count)
        {
            most.push_back(result_string);
        }
        else if (tmp > max_count)
        {
            max_count = tmp;
            most.clear();
            most.push_back(result_string);
        }
    }

    std::cout << std::endl << "Maximum Occurrences" << std::endl;
    for (std::vector<std::string>::const_iterator it = most.cbegin(); it != most.cend(); ++it)
        std::cout << *it << std::endl;

    return 0;
}
4

1 に答える 1

0

ここに表示されるクロス初期化:std::istringstream iss(std::move(string));

std::istringstream iss; 
iss.str(result_string);

std::istringstream iss(std::move(result_string));これは、問題を解決したことと同等です

@Dietmarが説明したように:

ここでは、std::string&& を取る str() オーバーロードはありませんが、std::string const& を取るものは 1 つだけです。結局のところ、ストリームはとにかく std::string を使用せず、文字を内部バッファーにコピーするだけです (std::string は、連続したメモリを使用してそれらの値を表すことが保証されているため、std:stringbuf が内部的に可能になります)。ほとんどの場合 std::string を使用しますが、ストリーム バッファーは少なくとも出力用に未使用のスペースを提供したいと考えていますが、バッファーは入力と出力の間で共有されます)。

于 2013-08-26T04:57:48.527 に答える