命令行读取参数

2023-05-16

有时需要从命令读取一些输入,这里找到一个方法,怎么实现的没有仔细研究,但是可用。
//cmdline.h

/*
  Copyright (c) 2009, Hideyuki Tanaka
  All rights reserved.
  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:
  * Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
  * Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.
  * Neither the name of the <organization> nor the
  names of its contributors may be used to endorse or promote products
  derived from this software without specific prior written permission.
  THIS SOFTWARE IS PROVIDED BY <copyright holder> ''AS IS'' AND ANY
  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <string>
#include <stdexcept>
#include <typeinfo>
#include <cstring>
#include <algorithm>
#include <cxxabi.h>
#include <cstdlib>

namespace cmdline{

namespace detail{

template <typename Target, typename Source, bool Same>
class lexical_cast_t{
public:
  static Target cast(const Source &arg){
    Target ret;
    std::stringstream ss;
    if (!(ss<<arg && ss>>ret && ss.eof()))
      throw std::bad_cast();
    
    return ret;
  }
};

template <typename Target, typename Source>
class lexical_cast_t<Target, Source, true>{
public:
  static Target cast(const Source &arg){
    return arg;
  }  
};

template <typename Source>
class lexical_cast_t<std::string, Source, false>{
public:
  static std::string cast(const Source &arg){
    std::ostringstream ss;
    ss<<arg;
    return ss.str();
  }
};

template <typename Target>
class lexical_cast_t<Target, std::string, false>{
public:
  static Target cast(const std::string &arg){
    Target ret;
    std::istringstream ss(arg);
    if (!(ss>>ret && ss.eof()))
      throw std::bad_cast();
    return ret;
  }
};

template <typename T1, typename T2>
struct is_same {
  static const bool value = false;
};

template <typename T>
struct is_same<T, T>{
  static const bool value = true;
};

template<typename Target, typename Source>
Target lexical_cast(const Source &arg)
{
  return lexical_cast_t<Target, Source, detail::is_same<Target, Source>::value>::cast(arg);
}

static inline std::string demangle(const std::string &name)
{
  int status=0;
  char *p=abi::__cxa_demangle(name.c_str(), 0, 0, &status);
  std::string ret(p);
  free(p);
  return ret;
}

template <class T>
std::string readable_typename()
{
  return demangle(typeid(T).name());
}

template <class T>
std::string default_value(T def)
{
  return detail::lexical_cast<std::string>(def);
}

template <>
inline std::string readable_typename<std::string>()
{
  return "string";
}

} // detail

//-----

class cmdline_error : public std::exception {
public:
  cmdline_error(const std::string &msg): msg(msg){}
  ~cmdline_error() throw() {}
  const char *what() const throw() { return msg.c_str(); }
private:
  std::string msg;
};

template <class T>
struct default_reader{
  T operator()(const std::string &str){
    return detail::lexical_cast<T>(str);
  }
};

template <class T>
struct range_reader{
  range_reader(const T &low, const T &high): low(low), high(high) {}
  T operator()(const std::string &s) const {
    T ret=default_reader<T>()(s);
    if (!(ret>=low && ret<=high)) throw cmdline::cmdline_error("range_error");
    return ret;
  }
private:
  T low, high;
};

template <class T>
range_reader<T> range(const T &low, const T &high)
{
  return range_reader<T>(low, high);
}

template <class T>
struct oneof_reader{
  T operator()(const std::string &s){
    T ret=default_reader<T>()(s);
    if (std::find(alt.begin(), alt.end(), ret)==alt.end())
      throw cmdline_error("");
    return ret;
  }
  void add(const T &v){ alt.push_back(v); }
private:
  std::vector<T> alt;
};

template <class T>
oneof_reader<T> oneof(T a1)
{
  oneof_reader<T> ret;
  ret.add(a1);
  return ret;
}

template <class T>
oneof_reader<T> oneof(T a1, T a2)
{
  oneof_reader<T> ret;
  ret.add(a1);
  ret.add(a2);
  return ret;
}

template <class T>
oneof_reader<T> oneof(T a1, T a2, T a3)
{
  oneof_reader<T> ret;
  ret.add(a1);
  ret.add(a2);
  ret.add(a3);
  return ret;
}

template <class T>
oneof_reader<T> oneof(T a1, T a2, T a3, T a4)
{
  oneof_reader<T> ret;
  ret.add(a1);
  ret.add(a2);
  ret.add(a3);
  ret.add(a4);
  return ret;
}

template <class T>
oneof_reader<T> oneof(T a1, T a2, T a3, T a4, T a5)
{
  oneof_reader<T> ret;
  ret.add(a1);
  ret.add(a2);
  ret.add(a3);
  ret.add(a4);
  ret.add(a5);
  return ret;
}

template <class T>
oneof_reader<T> oneof(T a1, T a2, T a3, T a4, T a5, T a6)
{
  oneof_reader<T> ret;
  ret.add(a1);
  ret.add(a2);
  ret.add(a3);
  ret.add(a4);
  ret.add(a5);
  ret.add(a6);
  return ret;
}

template <class T>
oneof_reader<T> oneof(T a1, T a2, T a3, T a4, T a5, T a6, T a7)
{
  oneof_reader<T> ret;
  ret.add(a1);
  ret.add(a2);
  ret.add(a3);
  ret.add(a4);
  ret.add(a5);
  ret.add(a6);
  ret.add(a7);
  return ret;
}

template <class T>
oneof_reader<T> oneof(T a1, T a2, T a3, T a4, T a5, T a6, T a7, T a8)
{
  oneof_reader<T> ret;
  ret.add(a1);
  ret.add(a2);
  ret.add(a3);
  ret.add(a4);
  ret.add(a5);
  ret.add(a6);
  ret.add(a7);
  ret.add(a8);
  return ret;
}

template <class T>
oneof_reader<T> oneof(T a1, T a2, T a3, T a4, T a5, T a6, T a7, T a8, T a9)
{
  oneof_reader<T> ret;
  ret.add(a1);
  ret.add(a2);
  ret.add(a3);
  ret.add(a4);
  ret.add(a5);
  ret.add(a6);
  ret.add(a7);
  ret.add(a8);
  ret.add(a9);
  return ret;
}

template <class T>
oneof_reader<T> oneof(T a1, T a2, T a3, T a4, T a5, T a6, T a7, T a8, T a9, T a10)
{
  oneof_reader<T> ret;
  ret.add(a1);
  ret.add(a2);
  ret.add(a3);
  ret.add(a4);
  ret.add(a5);
  ret.add(a6);
  ret.add(a7);
  ret.add(a8);
  ret.add(a9);
  ret.add(a10);
  return ret;
}

//-----

class parser{
public:
  parser(){
  }
  ~parser(){
    for (std::map<std::string, option_base*>::iterator p=options.begin();
         p!=options.end(); p++)
      delete p->second;
  }

  void add(const std::string &name,
           char short_name=0,
           const std::string &desc=""){
    if (options.count(name)) throw cmdline_error("multiple definition: "+name);
    options[name]=new option_without_value(name, short_name, desc);
    ordered.push_back(options[name]);
  }

  template <class T>
  void add(const std::string &name,
           char short_name=0,
           const std::string &desc="",
           bool need=true,
           const T def=T()){
    add(name, short_name, desc, need, def, default_reader<T>());
  }

  template <class T, class F>
  void add(const std::string &name,
           char short_name=0,
           const std::string &desc="",
           bool need=true,
           const T def=T(),
           F reader=F()){
    if (options.count(name)) throw cmdline_error("multiple definition: "+name);
    options[name]=new option_with_value_with_reader<T, F>(name, short_name, need, def, desc, reader);
    ordered.push_back(options[name]);
  }

  void footer(const std::string &f){
    ftr=f;
  }

  void set_program_name(const std::string &name){
    prog_name=name;
  }

  bool exist(const std::string &name) const {
    if (options.count(name)==0) throw cmdline_error("there is no flag: --"+name);
    return options.find(name)->second->has_set();
  }

  template <class T>
  const T &get(const std::string &name) const {
    if (options.count(name)==0) throw cmdline_error("there is no flag: --"+name);
    const option_with_value<T> *p=dynamic_cast<const option_with_value<T>*>(options.find(name)->second);
    if (p==NULL) throw cmdline_error("type mismatch flag '"+name+"'");
    return p->get();
  }

  const std::vector<std::string> &rest() const {
    return others;
  }

  bool parse(const std::string &arg){
    std::vector<std::string> args;

    std::string buf;
    bool in_quote=false;
    for (std::string::size_type i=0; i<arg.length(); i++){
      if (arg[i]=='\"'){
        in_quote=!in_quote;
        continue;
      }

      if (arg[i]==' ' && !in_quote){
        args.push_back(buf);
        buf="";
        continue;
      }

      if (arg[i]=='\\'){
        i++;
        if (i>=arg.length()){
          errors.push_back("unexpected occurrence of '\\' at end of string");
          return false;
        }
      }

      buf+=arg[i];
    }

    if (in_quote){
      errors.push_back("quote is not closed");
      return false;
    }

    if (buf.length()>0)
      args.push_back(buf);

    for (size_t i=0; i<args.size(); i++)
      std::cout<<"\""<<args[i]<<"\""<<std::endl;

    return parse(args);
  }

  bool parse(const std::vector<std::string> &args){
    int argc=static_cast<int>(args.size());
    std::vector<const char*> argv(argc);

    for (int i=0; i<argc; i++)
      argv[i]=args[i].c_str();

    return parse(argc, &argv[0]);
  }

  bool parse(int argc, const char * const argv[]){
    errors.clear();
    others.clear();

    if (argc<1){
      errors.push_back("argument number must be longer than 0");
      return false;
    }
    if (prog_name=="")
      prog_name=argv[0];

    std::map<char, std::string> lookup;
    for (std::map<std::string, option_base*>::iterator p=options.begin();
         p!=options.end(); p++){
      if (p->first.length()==0) continue;
      char initial=p->second->short_name();
      if (initial){
        if (lookup.count(initial)>0){
          lookup[initial]="";
          errors.push_back(std::string("short option '")+initial+"' is ambiguous");
          return false;
        }
        else lookup[initial]=p->first;
      }
    }

    for (int i=1; i<argc; i++){
      if (strncmp(argv[i], "--", 2)==0){
        const char *p=strchr(argv[i]+2, '=');
        if (p){
          std::string name(argv[i]+2, p);
          std::string val(p+1);
          set_option(name, val);
        }
        else{
          std::string name(argv[i]+2);
          if (options.count(name)==0){
            errors.push_back("undefined option: --"+name);
            continue;
          }
          if (options[name]->has_value()){
            if (i+1>=argc){
              errors.push_back("option needs value: --"+name);
              continue;
            }
            else{
              i++;
              set_option(name, argv[i]);
            }
          }
          else{
            set_option(name);
          }
        }
      }
      else if (strncmp(argv[i], "-", 1)==0){
        if (!argv[i][1]) continue;
        char last=argv[i][1];
        for (int j=2; argv[i][j]; j++){
          last=argv[i][j];
          if (lookup.count(argv[i][j-1])==0){
            errors.push_back(std::string("undefined short option: -")+argv[i][j-1]);
            continue;
          }
          if (lookup[argv[i][j-1]]==""){
            errors.push_back(std::string("ambiguous short option: -")+argv[i][j-1]);
            continue;
          }
          set_option(lookup[argv[i][j-1]]);
        }

        if (lookup.count(last)==0){
          errors.push_back(std::string("undefined short option: -")+last);
          continue;
        }
        if (lookup[last]==""){
          errors.push_back(std::string("ambiguous short option: -")+last);
          continue;
        }

        if (i+1<argc && options[lookup[last]]->has_value()){
          set_option(lookup[last], argv[i+1]);
          i++;
        }
        else{
          set_option(lookup[last]);
        }
      }
      else{
        others.push_back(argv[i]);
      }
    }

    for (std::map<std::string, option_base*>::iterator p=options.begin();
         p!=options.end(); p++)
      if (!p->second->valid())
        errors.push_back("need option: --"+std::string(p->first));

    return errors.size()==0;
  }

  void parse_check(const std::string &arg){
    if (!options.count("help"))
      add("help", '?', "print this message");
    check(0, parse(arg));
  }

  void parse_check(const std::vector<std::string> &args){
    if (!options.count("help"))
      add("help", '?', "print this message");
    check(args.size(), parse(args));
  }

  void parse_check(int argc, char *argv[]){
    if (!options.count("help"))
      add("help", '?', "print this message");
    check(argc, parse(argc, argv));
  }

  std::string error() const{
    return errors.size()>0?errors[0]:"";
  }

  std::string error_full() const{
    std::ostringstream oss;
    for (size_t i=0; i<errors.size(); i++)
      oss<<errors[i]<<std::endl;
    return oss.str();
  }

  std::string usage() const {
    std::ostringstream oss;
    oss<<"usage: "<<prog_name<<" ";
    for (size_t i=0; i<ordered.size(); i++){
      if (ordered[i]->must())
        oss<<ordered[i]->short_description()<<" ";
    }
    
    oss<<"[options] ... "<<ftr<<std::endl;
    oss<<"options:"<<std::endl;

    size_t max_width=0;
    for (size_t i=0; i<ordered.size(); i++){
      max_width=std::max(max_width, ordered[i]->name().length());
    }
    for (size_t i=0; i<ordered.size(); i++){
      if (ordered[i]->short_name()){
        oss<<"  -"<<ordered[i]->short_name()<<", ";
      }
      else{
        oss<<"      ";
      }

      oss<<"--"<<ordered[i]->name();
      for (size_t j=ordered[i]->name().length(); j<max_width+4; j++)
        oss<<' ';
      oss<<ordered[i]->description()<<std::endl;
    }
    return oss.str();
  }

private:

  void check(int argc, bool ok){
    if ((argc==1 && !ok) || exist("help")){
      std::cerr<<usage();
      exit(0);
    }

    if (!ok){
      std::cerr<<error()<<std::endl<<usage();
      exit(1);
    }
  }

  void set_option(const std::string &name){
    if (options.count(name)==0){
      errors.push_back("undefined option: --"+name);
      return;
    }
    if (!options[name]->set()){
      errors.push_back("option needs value: --"+name);
      return;
    }
  }

  void set_option(const std::string &name, const std::string &value){
    if (options.count(name)==0){
      errors.push_back("undefined option: --"+name);
      return;
    }
    if (!options[name]->set(value)){
      errors.push_back("option value is invalid: --"+name+"="+value);
      return;
    }
  }

  class option_base{
  public:
    virtual ~option_base(){}

    virtual bool has_value() const=0;
    virtual bool set()=0;
    virtual bool set(const std::string &value)=0;
    virtual bool has_set() const=0;
    virtual bool valid() const=0;
    virtual bool must() const=0;

    virtual const std::string &name() const=0;
    virtual char short_name() const=0;
    virtual const std::string &description() const=0;
    virtual std::string short_description() const=0;
  };

  class option_without_value : public option_base {
  public:
    option_without_value(const std::string &name,
                         char short_name,
                         const std::string &desc)
      :nam(name), snam(short_name), desc(desc), has(false){
    }
    ~option_without_value(){}

    bool has_value() const { return false; }

    bool set(){
      has=true;
      return true;
    }

    bool set(const std::string &){
      return false;
    }

    bool has_set() const {
      return has;
    }

    bool valid() const{
      return true;
    }

    bool must() const{
      return false;
    }

    const std::string &name() const{
      return nam;
    }

    char short_name() const{
      return snam;
    }

    const std::string &description() const {
      return desc;
    }

    std::string short_description() const{
      return "--"+nam;
    }

  private:
    std::string nam;
    char snam;
    std::string desc;
    bool has;
  };

  template <class T>
  class option_with_value : public option_base {
  public:
    option_with_value(const std::string &name,
                      char short_name,
                      bool need,
                      const T &def,
                      const std::string &desc)
      : nam(name), snam(short_name), need(need), has(false)
      , def(def), actual(def) {
      this->desc=full_description(desc);
    }
    ~option_with_value(){}

    const T &get() const {
      return actual;
    }

    bool has_value() const { return true; }

    bool set(){
      return false;
    }

    bool set(const std::string &value){
      try{
        actual=read(value);
        has=true;
      }
      catch(const std::exception &e){
        return false;
      }
      return true;
    }

    bool has_set() const{
      return has;
    }

    bool valid() const{
      if (need && !has) return false;
      return true;
    }

    bool must() const{
      return need;
    }

    const std::string &name() const{
      return nam;
    }

    char short_name() const{
      return snam;
    }

    const std::string &description() const {
      return desc;
    }

    std::string short_description() const{
      return "--"+nam+"="+detail::readable_typename<T>();
    }

  protected:
    std::string full_description(const std::string &desc){
      return
        desc+" ("+detail::readable_typename<T>()+
        (need?"":" [="+detail::default_value<T>(def)+"]")
        +")";
    }

    virtual T read(const std::string &s)=0;

    std::string nam;
    char snam;
    bool need;
    std::string desc;

    bool has;
    T def;
    T actual;
  };

  template <class T, class F>
  class option_with_value_with_reader : public option_with_value<T> {
  public:
    option_with_value_with_reader(const std::string &name,
                                  char short_name,
                                  bool need,
                                  const T def,
                                  const std::string &desc,
                                  F reader)
      : option_with_value<T>(name, short_name, need, def, desc), reader(reader){
    }

  private:
    T read(const std::string &s){
      return reader(s);
    }

    F reader;
  };

  std::map<std::string, option_base*> options;
  std::vector<option_base*> ordered;
  std::string ftr;

  std::string prog_name;
  std::vector<std::string> others;

  std::vector<std::string> errors;
};

} // cmdline

//test,cpp

#include <signal.h>
#include <string.h>
#include "cmdline.h"
/*
    ./t_proxy_server -p 3333
*/
using namespace std;
int main(int argc, char *argv[]){
      
    cmdline::parser a;
    a.add<string>("host", 'h', "host name", false, "0.0.0.0");
    a.add<uint16_t>("port", 'p', "port number", false, 3333, cmdline::range(1, 65535));
    a.parse_check(argc, argv); 
    std::string host=a.get<string>("host");
    uint16_t port=a.get<uint16_t>("port");
    std::cout<<"host:"<<host<<std::endl;
    std::cout<<"port:"<<port<<std::endl;
    return 0;
}

运行结果:
1、默认情况,啥也不输入
在这里插入图片描述

2、根据提示,输入指定参数
在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

命令行读取参数 的相关文章

  • lxc

    LXC为Linux Container的简写 Linux Container容器是一种内核 虚拟化技术 xff0c 可以提供轻量级的虚拟化 xff0c 以便隔离进程和资源 xff0c 而且不需要提供指令解释机制以及全虚拟化的其他复杂性 相当
  • 关于ros2、turtlebot3和nav2的应用总结

    关于ros2 turtlebot3和nav2的应用总结 一 资源简介 1 版本要求 ros2 foxy turtlebot3 waffle nav2 0 4 1 gazebo gazebo ros pkgs 3 5 0 zip 2 资源链接
  • motion_primitive_library导航源码阅读笔记

    一 motion primitive library导航源码阅读笔记 二 路径规划文献 Search based Motion Planning for Quadrotors using Linear Quadratic Minimum T
  • Linux下安装cmake步骤详解(图文)

    1 查看Linux位数 getconf LONG BIT 2 获cmake源码包 这里我先新建一个文件夹来存放cmake mkdir app cd app wget https cmake org files v3 3 cmake 3 3
  • cartographer代码流程整理

    代码解析地址 https zhuanlan zhihu com p 48010119 一 代码目录结构 1 cartographer ros 2 cartographer 二 测试命令 2D xff1a roslaunch cartogra
  • 关于ros2、webots的应用总结

    关于ros2 webots的应用总结 一 资源简介 1 版本要求 ubuntu20 04 1 ros2 foxy 2 资源链接 webots官网 xff1a http www cyberbotics com webots ros2网址 xf
  • 日常使用书签

    1 TensorFlow API 中 NCHW 与 NHWC 的区别 https blog csdn net weixin 41847115 article details 83794551 utm medium 61 distribute
  • 在ubuntu下安装opencv4.5.1详细步骤

    1 到https github com opencv opencv下载opencv4 5 1 xff0c 解压得到opencv master 2 安装依赖包 sudo apt get install build essential cmak
  • 路径规划资料

    1 RRT算法原理图解 https blog csdn net weixin 43465857 article details 96451631 2 最透彻的A 算法详解 https my oschina net u 4847229 blo
  • nav2阅读笔记

    1 机器人起始坐标是在全局地图中 xff0c 目标点也在全局地图中 xff0c 全局路径规划在全局地图完成 机器人的运动控制是在局部地图中完成 xff0c 也就是在车体坐标系下 2 无人机 自动驾驶车辆全局路径规划 局部路径规划都是在全局坐
  • 日常使用标签2

    日常使用标签2 1 CUDA入门教程 https blog csdn net luoganttcc article details 123474189
  • 人工智能概述

    目录 什么是人工智能实现人工智能的方法逻辑编程机器学习深度学习机器学习和深度学习的区别 人工智能的分类如何实现人工智能 什么是人工智能 人工智能 又被称为机器智能 xff0c 是一种综合计算机科学 统计学 语言学等多种学科 xff0c 使机
  • 2019了,转行学编程过时了吗?

    最近 xff0c 我的一篇文章 现在学Java的人都是傻子 引起了一些网友讨论 xff0c 都在说现在学Java过时了 xff0c Java市场趋于饱和了 xff0c 应该弃学Java xff0c xff0c 难道Java编程真的过时了 x
  • 什么是用户态和内核态?用户态和内核态是如何切换的?

    3 什么是用户态和内核态 xff1f 用户态和内核态是操作系统的两种运行状态 xff0c 操作系统主要是为了对访问能力进行限制 xff0c 用户态的权限较低 xff0c 而内核态的权限较高 用户态 xff1a 用户态运行的程序只能受限地访问
  • ubuntu安装Clamav

    一 简介 Clam AntiVirus是一个类UNIX系统上使用的反病毒软件包 主要应用于邮件服务器 xff0c 采用多线程后台操作 xff0c 可以自动升级病毒库 ClamAV是一个在命令行下查毒软件 xff0c 因为它不将杀毒作为主要功
  • 什么是上下文切换?

    上下文切换指的是内核操作系统的核心在CPU上对进程或者线程进行切换 搞清楚上下文切换需要先搞清楚什么是上下文 CPU在开始执行任务时需要先知道从哪里去加载任务 xff0c 从哪里开始执行 xff0c 上下文的作用就是告诉CPU这些 xff0
  • ubuntu16.04下,ROS+PX4+QGC安装

    ubuntu16 04下 xff0c ROS 43 PX4 43 QGC安装 ROS安装 xff1a 第一步 xff1a ROS安装前准备工作 1 在Ubuntu系统上 xff0c 确认git已经安装 span class token fu
  • TokenEndpoint : Handling Null Pointer Exception

    springboot oauth2 0生成token时报错 详细的日志没有打印出来 需要手动配置log 64 Override public void configure AuthorizationServerEndpointsConfig
  • linux(ubuntu)无法连接网络

    提示 xff1a 版本 xff1a ubuntu16 0 4 问题 xff1a 开机没有网络 xff0c 无法连接网络 xff0c 尝试了很多方法最终才可以 首先查看ifconfig 查看网卡信息 ifconfig 查看ip ip a 查看
  • 八皇后问题

    问题描述 在国际象棋中 xff0c 有一个非常强势的棋子 皇后 xff0c 他的走法可以在网上参考一下 xff0c 概括来说就是可以沿着行 列 与对角线平行的线走 而在计算机中有一个关于他的经典问题 xff0c 8皇后 xff0c 就是在8

随机推荐

  • ubuntu18.04.3如何在终端下切换到指定文件夹或根目录

    看到很多的新手 xff0c 不知道如何在终端切换到根目录的 xff0c 或者是指定的目录的 xff0c 下面介绍一下切换的方法 1 先按键盘 ctrl 43 alt 43 t 弹出终端 xff0c 那么你会看到终端上的提示当前目录为 这个就
  • MySql简单查询——单表查询

    一 DDL xff08 Data Definition Language xff09 xff1a 数据定义语言 xff0c 用来定义数据库对象 xff1a 库 表 列等 xff1b 相关字段 xff1a create drop alter
  • linux下可视化git工具git-cola安装与使用(HTTP方式)

    一 git cola为何物 很多小伙伴 xff0c 特别喜欢使用TortoiseGit xff0c 该软件是做什么的 xff0c 就不用多说吧 奈何 xff0c TortoiseGit只有windows版 xff0c 这让在linux上开发
  • 解决ubuntu下应用程序菜单不在程序的左上角

    测试版本 xff1a ubuntu16 04 问题 xff1a 应用程序菜单不在程序的左上角 xff0c 默认放在了桌面顶部的菜单栏上 如下 xff1a 解决办法 xff1a System Settings gt Appearance gt
  • linux下可视化git工具git-cola安装与使用(SSH方式)

    一 git cola为何物 很多小伙伴 xff0c 特别喜欢使用TortoiseGit xff0c 该软件是做什么的 xff0c 就不用多说吧 奈何 xff0c TortoiseGit只有windows版 xff0c 这让在linux上开发
  • CAS实现SSO单点登录原理

    yale cas可以百度一下 xff0c 这是学习cas后的一点总结 xff0c 以备日后使用 xff01 安全性 xff1a 用户只须在cas录入用户名和密码 xff0c 之后通过ticket绑定用户 xff0c 在cas客户端与cas校
  • 五种知网文献免费下载方式

    1 idata中国知网 网址 xff1a idata中国知网 进入系统 xff0c 注册账号 xff0c 登录即可 每天五篇额度 xff0c 基本够用 xff0c 可注册多个账号使用 2 上海研发公共服务平台 网址 xff1a 上海研发公共
  • 【FreeRTOS】二值信号量实现线程的同步

    FreeRTOS 二值信号量实现线程的同步 测试环境如下 stm32L431RCT6 MDK keil5 stm32cube 43 FreeRTOS 一 添加多个任务 1 引脚配置 LED使用的引脚PA8和PB2设置成output 将按键引
  • 暗影精灵2pro安装win10+ubuntu16.10双系统

    暗影精灵2pro预装win10家庭版 xff0c 默认启动win10系统 xff0c 且无法引导其他系统 xff0c 今天我们来解决这个问题 先进入到win10的磁盘管理器服务 xff0c 为ubuntu单独分配磁盘空间 xff0c 让wi
  • 第二十三讲.从HadoopURL中读取数据

    视频 xff1a 美妙人生 Hadoop课程系列之HDFS 手把手教你精通HDFS 美妙人生 Hadoop课程系列之HDFS 手把手教你精通HDFS 视频笔记 从hadoop URL读取数据 static URL setURLStreamH
  • winform窗体

    一 winform介绍 WinForm xff0c 是 Net开发平台中对Windows Form的一种称谓 WinForm是窗体应用程序 xff0c 由若干个窗体应用组成 xff0c 基于C S架构 二 winform的使用 xff08
  • 赋予人工智能记忆的人,带你梳理深度学习核心算法

    新智元翻译 1 来源 xff1a Idsia 作者 xff1a J rgen Schmidhuber 翻译 xff1a 张巨岩 作者介绍 xff1a J rgen Schmidhuber 被称为是赋予人工智能记忆的人 xff0c 递归神经网
  • C++实现贪吃蛇游戏

    注意 xff1a 本代码是在VC 43 43 6 0环境下编译的 xff0c 在其他环境如codeblocks下运行可能会产生意想不到的问题 xff0c 请尽量使用VC xff01 最近由于小编闲着慌 xff0c 捣鼓了一个贪吃蛇游戏 xf
  • Win10正式版19044.2132(KB5020435)来啦!(附完整更新日志)

    微软发布了Win10正式版KB5020435 xff08 操作系统内部版本 19042 2132 19043 2132 和 19044 2132 xff09 xff0c 此次更新主要解决了某些类型的安全套接字层 xff08 SSL xff0
  • SOUI总结之皮肤说明

    皮肤说明 说明 框架自带的皮肤都是 skin sys XXXX开始 xff0c 自带的皮肤存放位置trunk soui sys resource theme sys res xff0c 图片和名称映射关系可以打开trunk soui sys
  • C++中逗号运算符

    今天测试代码的时候 xff0c 遇到一行代码出现了疑问 xff0c 原因是出现了自减运算符和逗号运算符 xff0c 这就涉及到一个顺序的问题 xff0c 于是写了一个C 43 43 小程序 xff0c 验证了一下这个想法 include u
  • PsExec的问题及其解决办法

    C gt PsExec exe 192 168 1 142 cmd PsExec v1 98 Execute processes remotely Copyright C 2001 2010 Mark Russinovich Sysinte
  • ubuntu 18.04安装protobuf

    今天需要安装protobuf 在网上搜了一篇教程 xff0c 但是篇幅太长 xff0c 于是对其进行简化一下 原文 1 96 96 96 git clone https github com protocolbuffers protobuf
  • 读取配置文件的程序

    时常会遇到需要从配置文件中读取一些信息 xff0c 这里就提供一个例子 xff0c 方便日后使用 xff1a span class token comment ini h span span class token macro proper
  • 命令行读取参数

    有时需要从命令读取一些输入 xff0c 这里找到一个方法 xff0c 怎么实现的没有仔细研究 xff0c 但是可用 cmdline h span class token comment Copyright c 2009 Hideyuki T