2017-02-11 44 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++库输入的字符数量。

相关问题