2015-09-28 97 views
0

我在UNIX終端運行此程序,但是當我嘗試編譯它給出了一個巨大的問題清單,但是我相信這個問題是部分說敵不過運營>>。我知道程序中遺漏了很多它不是接近完成,我想能夠編譯它,我雖然走更遠了。我不知道是什麼導致這個錯誤的任何幫助,不勝感激。不匹配運營商>>問題

#include <iostream> 
#include <vector> 
#include <string> 

using namespace std; 

int main() 
{ 
    int ui = 0 ; 
    vector<string> in; 
    string temp = "0"; 
    int vsize = 0; 

    while(ui != 5) 
    { 
      cout << "1.  Read" << endl; 
      cout << "2.  Print" << endl; 
      cout << "3.  Sort" << endl; 
      cout << "4.  Search" << endl; 
      cout << "5.  Quit" << endl; 
      std::cin >> ui >> std::endl; 

      if(ui = 1) 
      { 
        while(temp != "q") 
        { 
          std::cout << "Enter the next element (Enter 'q' to stop):" << std::endl; 
          std::cin >> temp >> std::endl; 
          in.pushback(temp); 
          vsize++; 
        } 
      } 

      if(ui = 2) 
      { 
        std::cout << "Sequence: "; 
        for (int i = 0; i < vsize; i++) 
        { 
          cout << in[i]; 
        } 
        std::cout << std::endl; 
      } 

      if(ui = 3) 
      { 
      } 
    } 
    return 0; 

}

+4

'std :: cin >> temp >> std :: endl;'你是否試圖將數據讀入'endl'? – John3136

+1

請在發佈時提供相關信息。這包括*完整的錯誤信息*。 –

+1

*「......我希望能夠在我進一步深入之前編譯它......」*良好的直覺;你應該在沒有任何警告的情況下編譯它,然後再進一步*你甚至可以退到一個更簡單的版本,直到你解決這個問題。 – Beta

回答

1

你知道你在你的if語句做任務?在C++中用平等寫作==。另外,爲什麼vsize?矢量有自己的方法用於獲取大小,in.size()會這樣想的。

0

我想能夠編譯它之前,我走得更遠...不錯!

但是你應該閱讀錯誤和警告消息,他們經常幫助瞭解問題並解決它的辦法(以下使用鐺輸出):

ess.cpp:21:31: error: reference to overloaded function could not be resolved; 
    did you mean to call it? 
     std::cin >> ui >> std::endl; 

您正在試圖提取的東西進入std::endl這是無意義的。只要寫std::cin >> ui;

ess.cpp:23:19: warning: using the result of an assignment as a condition without 
    parentheses [-Wparentheses] 
     if(ui = 1) 

ui = 1是一個賦值。平等的測試應該是if (ui == 1)

ess.cpp:29:32: error: no member named 'pushback' in 
    'std::__1::vector<std::__1::basic_string<char, 
    std::__1::char_traits<char>, std::__1::allocator<char> >, 
    std::__1::allocator<std::__1::basic_string<char, 
    std::__1::char_traits<char>, std::__1::allocator<char> > > >'; did you 
    mean 'push_back'? 
         in.pushback(temp); 

...我認爲太,你沒有意思in.push_back(temp);

我只用了一次,例如爲每個錯誤,你應該能夠解決重複:-)