2017-02-11 27 views
0

我在做一個賦值,其中我正在創建一個處理主內存的文本編輯器。我不允許使用文件處理,我也不允許使用字符串類的字符串庫或cstring庫。 現在我必須實現的是,一行只包含60個字符,如果用戶超過60個字符的輸入,它應該自動轉移到下一行,我也必須顯示行號,而用戶正在給輸入 我的代碼是在這裏如果用戶超過特定字符數,則更改行

#include <iostream> 
using namespace std; 

int main() 
{ 
    char***files=new char**[50]; 
    char**fileNames=new char*[50]; 
    int fileCount=0; 
    while (true) 
    { 
     int selector=0; 
     cout<<"MacMAds Notepad"<<endl<<endl; 
     cout<<"Press 1. To Create a new file"<<endl; 
     cout<<"Press 2. To View an existing file by giving file name"<<endl; 
     cout<<"Press 3. To edit an existing file by giving its name"<<endl; 
     cout<<"Press 4. To copy an existing file to a new file"<<endl; 
     cout<<"Press 5. To delete an existing file by giving its name"<<endl; 
     cout<<"Press 6. To view listof all files with the names"<<endl; 
     cout<<"Press7. To Exit" 
     cin>>selector; 
     if (selector==7) 
      break; 
     if (selector==1) 
     { 
      cout<<"Please enter the name of file: "; 
      cin>>fileNames[fileCount]; 
      int nLines=0; 
      cout<<"Please enter the number of lines for "<<fileNames[fileCount]<<": "; 
      cin>>nLines; 
      files[fileCount]=new char*[nLines]; 
      for (int i=0;i<nLines;i++) 
      { 
       files[fileCount][i]=new char[61]; 
       cin.getline(files[fileCount][i],60) 
      } 

        } 
    } 
    return 0; 
} 
+1

我們不會爲您編寫該代碼。自己嘗試一下,我們可能會爲您遇到的具體問題提供幫助。 –

+0

其實我想知道哪些庫和函數可以實現這一點,因爲我dnt的cin.getline將實現這個 –

+0

你被限制不使用任何這些?那麼我沒有得到你想要的東西。 –

回答

0
現在我要實現

是單行只包含60個字符,如果用戶超過輸入60個字符,它會自動切換到下一行

你不能這樣做使用標準的C++ buffe紅色輸入從std::cinstd::getline(),因爲所有輸入需要使用ENTER鍵來觸發。

您需要攔截任何按鍵直接掃描鍵盤輸入事件。這是OS特定的功能,C++標準庫不包含這些功能。

雖然有像ncurses這樣的第三方庫,但它們允許您以平臺獨立的方式進行操作。

+0

請你詳細說明一下ncurses,因爲我是新手 –

+0

@MuhammadAbdullahCheema檢查[鏈接](https://www.gnu.org/software/guile-ncurses/manual/html_node/Getting-characters-from-the- keyboard.html)。這應該足夠詳盡。 –

0

您不能限制用戶通過標準C++庫輸入的字符數量。

相關問題