2017-02-23 48 views
0

我無法獲得該程序進行編譯。我通過自動啓動和自動結束得到一個錯誤。沒有一個類型的名稱。我也試圖讓findwordfindchar在這個程序中工作。任何意見將不勝感激。關於創建單詞,字母,字符計數函數的錯誤n findword,findchar

#include <iostream> 
#include <string> 
#include <stdio.h> 

using namespace std; 

int main(int argc, const char * argv[]) { 

    string allWords; 

    int lineCharacterCount = 0; 

    int maxCharacterCount = 60; 

    int charactersRemaining = 0; 

    string delimiter = " "; 

    string word; 

    string sentense; 

    int remainder = 0; 

    getline(cin, allWords); 

    auto start = 0U; 
    auto end = allWords.find(delimiter); 
    while (end != string::npos) 
    { 
     word = allWords.substr(start, end - start); 

     if (((word.length() + 1) + lineCharacterCount) < maxCharacterCount) 
     { 
      sentense.append(word); 
      sentense.append(" "); 
      lineCharacterCount += word.length() + 1; 

      start = end + delimiter.length(); 
      end = allWords.find(delimiter, start); 
     } 
     else 
     { 
      word = allWords.substr(start, end - start); 

      // Note to myself: Find how many characters are remaining to reach maxCharacterCount minus 1 for the hyphen 
      charactersRemaining = (maxCharacterCount - lineCharacterCount) - 1; 
      if ((word.length() - charactersRemaining) > 0) 
      { 
       sentense.append(word.substr(0, charactersRemaining)); 
       sentense.append("-"); 
       remainder += 1; 
      } 

      cout << sentense << endl; 
      sentense = ""; 
      lineCharacterCount = 0; 

      if (remainder) 
      { 
       sentense.append(word.substr(charactersRemaining, string::npos)); 
       sentense.append(" "); 
       lineCharacterCount += word.length() + 1; 
       remainder = 0; 
      } 

      start = end + delimiter.length(); 
      end = allWords.find(delimiter, start); 
     } 
    } 

    word = allWords.substr(start, end - start); 
    sentense.append(word); 

    cout << sentense << endl; 

    return 0; 
} 
+1

您正在使用C++編譯器的11? –

+0

我相信,我是 – Neil

+0

它絕對看起來好像你正在編譯C++ 03標準。使用g ++添加選項'-std = C++ 11'或者'-std = C++ 14',如果你有版本支持它的話。要獲得更詳細的幫助,請包括**相關信息**,例如您的編譯器和verision,您使用構建的命令(以及任何相關環境變量或編譯器的其他配置)以及逐字引用的診斷。 –

回答

0

設置編譯器標誌-std = C++ 11