我曾经用 sublime 打开文本文件,对于只读文件,我曾经这样做 :
sudo sublime。但现在突然sudo sublime命令给出以下错误:
(sublime:3931): Gtk-WARNING **: cannot open display:
Run Code Online (Sandbox Code Playgroud)
而sublime命令工作正常。我尝试了同样的gedit,并且发生了同样的事情,显示了 gedit 的错误:
error: XDG_RUNTIME_DIR not set in the environment.
(gedit:3933): Gtk-WARNING **: cannot open display:
Run Code Online (Sandbox Code Playgroud)
我安装了gtk,试过了gksudo,还是出现同样的错误!
我在网上搜索并找到了以下方法:
xhost +localhost: https://askubuntu.com/questions/614387/gksu-gtk-warning-cannot-open-display-0export DISPLAY=:0.0 : ssh username@hostname -Xssh username@hostname -Y以上都没有奏效。
对我有用的是:
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY sublime
Run Code Online (Sandbox Code Playgroud)
从这里:https : //askubuntu.com/questions/456689/error-xdg-runtime-dir-not-set-in-the-environment-when-attempting-to-run-naut
我想知道为什么我会收到这个错误,太突然了!另外,我想回到这个sudo sublime版本,因为它很容易记住。我该如何解决?
此外,我最近对系统所做的更改是:
为 Ubuntu 安装 Mac 主题:http : //www.noobslab.com/2014/04/macbuntu-1404-pack-is-released.html …
我最近碰到一个高尔夫球编码来到†中,我还以为写类型的函数问题int中main本身,它可以访问内部主要的变量.但是为了减少字符数,我想到了一个函数和一个变量.像这样的东西:
int i,f(){/*function code*/};
Run Code Online (Sandbox Code Playgroud)
我可以这样做吗?如果是/否,那么为什么?
† Code Golf是一种休闲节目,其中必须以最短的节目解决特定的挑战.减少源代码中的字符数是主要目标,可维护性和可读性并不重要.请在评论之前考虑此目标.
我注意到很多次,无论什么时候需要为(新)分配值std::pair,都会std::make_pair被使用.但是我没有找到任何make_pair函数的使用,因为我们可以直接将值输入到一对,并根据需要修改它们.例如:
std::pair<int,int> newp;
std::cin>>newp.first>>newp.second;
newp.first = -1;
Run Code Online (Sandbox Code Playgroud)
那究竟是什么功能的使用?
如果需要使用我们自己的带有声明的头文件和带有定义的cpp文件来编译C或CPP编译程序,我们需要在编译命令中包含带有定义的cpp文件(请参阅此答案).但是,当我们编写时#include <iostream>,我们不会iostream.cpp在编译语句中包含像g++ main.cpp iostream.cpp -o main.
如果我们编写自定义声明文件,例如hello.hpp使用类声明和hello.cpp定义,我们需要使用g++ main.cpp hello.cpp -o mainafter包含hello.hpp在main.cpp文件的头文件中来编译它.为什么是这样?
编辑:我们可以模仿我们的自定义头文件和cpp文件的标准模板库的行为,这样我们所要做的就是包含头文件并自动编译声明吗?如果是,那怎么样?如果不是,为什么不呢?
这是我的C程序:
#include <stdio.h>
main(){ printf("%f", 5/3); }
Run Code Online (Sandbox Code Playgroud)
我期待输出1.000000,但我得到的输出是0.000000.有人可以解释原因吗?