Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c++;输入,直到通过键盘发出信号的输入结束 我想写一个C++(C,如果它提供了我的问题的简单解决方案)程序,在那里输入一个直到他选择输入信号结束时,按这样的按钮组合为CTRL+D。我对此有两个问题。 在Xterm中,哪些组合键用于表示输入结束?(Ctrl+C或Z不起作用)_C++_Logic_User Input_Xterm_G++ 4.7 - Fatal编程技术网

c++;输入,直到通过键盘发出信号的输入结束 我想写一个C++(C,如果它提供了我的问题的简单解决方案)程序,在那里输入一个直到他选择输入信号结束时,按这样的按钮组合为CTRL+D。我对此有两个问题。 在Xterm中,哪些组合键用于表示输入结束?(Ctrl+C或Z不起作用)

c++;输入,直到通过键盘发出信号的输入结束 我想写一个C++(C,如果它提供了我的问题的简单解决方案)程序,在那里输入一个直到他选择输入信号结束时,按这样的按钮组合为CTRL+D。我对此有两个问题。 在Xterm中,哪些组合键用于表示输入结束?(Ctrl+C或Z不起作用),c++,logic,user-input,xterm,g++-4.7,C++,Logic,User Input,Xterm,G++ 4.7,当按下1中回答的组合键时,while()循环中相应处理的逻辑代码应该是什么 map<int,string>info; string name; int age; cin>>name; while( ????????? ){ //Input till EOF , missing logic cin>>age; info.insert( pair<int,string>(age,name) ); cin>>nam

当按下1中回答的组合键时,while()循环中相应处理的逻辑代码应该是什么

map<int,string>info;
string name;
int age;
cin>>name;
while( ????????? ){   //Input till EOF , missing logic
    cin>>age;
    info.insert( pair<int,string>(age,name) );
    cin>>name;
}
//sorted o/p in reverse order
map<int,string> :: iterator i;
for(i=info.end(); i !=info.begin(); i--)
    cout<<(*i).second<<endl;
cout<<(*i).second<<endl;
mapinfo;
字符串名;
智力年龄;
cin>>名称;
当(????????){//输入到EOF时,缺少逻辑
cin>>年龄;
信息插入(配对(年龄、姓名));
cin>>名称;
}
//按相反顺序排序的o/p
迭代器i;
对于(i=info.end();i!=info.begin();i--)

coutwhile条件应类似于:

while(the_key_combination_pressed_in_the_last_loop!=what_combination_will_exit_while)
{
  cin>>age;
  if(age!=what_combination_will_exit_while)
  {
      info.insert( pair<int,string>(age,name) );
      cin>>name;
  }
}
while(上次循环中按的组合键)=何时退出组合键)
{
cin>>年龄;
如果(年龄)=什么组合将退出
{
信息插入(配对(年龄、姓名));
cin>>名称;
}
}

使用
istream\u迭代器

等待EOF的默认构造函数

i、 e
Ctrl+Z
或windows上的
F6+ENTER

Ctrl+D
在linux上

我将使用代理类动态插入map,如下所示:

#include <map>
#include <iterator>
#include <algorithm>
#include <string>
#include <functional>
#include <iostream>

template<class Pair>
class info_reader // Proxy class, for overloaded << operator
{
public:
        typedef Pair pair_type;

        friend std::istream& operator>>(std::istream& is, info_reader& p)
        {
              return is >> p.m_p.first >> p.m_p.second;
        }

        pair_type const& to_pair() const
        {
                return m_p; //Access the data member
        }
private:
        pair_type m_p;                
};


int main()
{
    typedef std::map<int, std::string> info_map;

    info_map info;
    typedef info_reader<std::pair<int, std::string> > info_p;

       // I used transform to directly read from std::cin and put into map
        std::transform(
            std::istream_iterator<info_p>(std::cin),
            std::istream_iterator<info_p>(),
            std::inserter(info, info.end()),
            std::mem_fun_ref(&info_p::to_pair) //Inserter function
                );

//Display map
for(info_map::iterator x=info.begin();x!=info.end();x++)
   std::cout<<x->first<< " "<<x->second<<std::endl;
}
#包括
#包括
#包括
#包括
#包括
#包括
模板
类信息读取器//代理类,用于重载>(std::istream&is,信息读取器&p)
{
返回值为>>下午第一>>下午第二;
}
配对类型常量和配对()常量
{
返回m_p;//访问数据成员
}
私人:
双U型m_p;
};
int main()
{
typedef std::map info_map;
信息(地图信息),;
typedef info_reader info_p;
//我使用transform直接读取std::cin并将其放入map
std::transform(
std::istream_迭代器(std::cin),
std::istream_迭代器(),
插入器(info,info.end()),
std::mem\u fun\u ref(&info\u p::to\u pair)//插入器函数
);
//显示地图
对于(info_map::迭代器x=info.begin();x!=info.end();x++)

STD::插入到map中并不是我关心的大问题。我想要一个C++逻辑SMTHG,比如<代码>(CIN > name){…} /CODE,在键组合被按下后停止对输入进行处理。但是显然这不起作用。请参阅其他代码。@上面的代码将与<代码> CTRL+D</代码>(Linux)一起工作。或者
Ctrl+Z
你想要其他的组合键吗?@POW我得到了第一部分wrt组合键的答案。但是我很难实现它。问题是使用相同的构造,如果它是字符串,我必须做任何事情,如果是该组合键,我必须退出。