2013-08-26 28 views
-1

最初我在while循環中寫了std::istringstream iss(std::move(string));,所以在內部循環中給出了錯誤crosses initialization。現在它不在任何循環中,但它也會給出錯誤crosses the initializationstd :: istringstream iss(std :: move(string));穿過初始化雖然它是在外側循環

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; 
} 
+0

這是在一個開關的情況下? – chris

+0

@chris:沒有沒有在開關 – user123

+0

@卡里姆汗,哦,錯誤的措辭讓我想起了那個問題。 – chris

回答

0

跨初始化出現在這裏:std::istringstream iss(std::move(string));

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

這相當於std::istringstream iss(std::move(result_string));解決問題

由於@Dietmar解釋說:

這裏沒有STR()過載取一個std :: string & &但只有一個採取std :: string const &。畢竟,流不會使用std :: string,只需將字符複製到其內部緩衝區中(std :: string現在可以保證使用連續的內存來表示它們的值,因此std:stringbuf可以在內部使用主要使用std :: string,但流緩衝區至少要提供未使用的空間用於輸出,但緩衝區在輸入和輸出之間共享)。

相關問題