小编Max*_*ahm的帖子

VIM:设定清单!作为.vimrc中的切换

我的.vimrc文件中是否有任何方法可以使用set list!带有键绑定的命令,F3因此它的功能类似于此粘贴切换set pastetoggle=<F2>.

vim

10
推荐指数
1
解决办法
4135
查看次数

Notepad++ 特殊字符串字符高亮

在记事本++中如果我有代码

 printf("Hello, World\n");
Run Code Online (Sandbox Code Playgroud)

整个字符串 '"Hello, World\n"' 是一种颜色,但在 vim 等编辑器中 '\n' 是不同的颜色,表示它是一个特殊字符。在记事本++中是否有这种行为?vim 的一个特别好的功能是突出显示一些陌生的 printf 语法,例如 '% 5.3s' 或 '%%'

printf highlighting notepad++

5
推荐指数
1
解决办法
1635
查看次数

如何从C++中的向量中删除几乎重复的内容

我有一个浮点数的std :: vector我想不包含重复项,但是填充向量的数学运算不是100%精确的.向量的值相差几百,但应视为相同的点.例如,这里有一些值:

...
X: -43.094505
X: -43.094501
X: -43.094498
...
Run Code Online (Sandbox Code Playgroud)

从这样的向量中删除重复项的最佳/最有效方法是什么.

c++ vector floating-accuracy duplicates duplicate-removal

3
推荐指数
1
解决办法
864
查看次数

使用大括号C++填充动态数组

在c ++中有没有办法填充像这样分配的数组

int **a = new int[4][2];
Run Code Online (Sandbox Code Playgroud)

这样就可以在一行中填充值

int a [4][2] = {{2,3,4},{5,6,7}};
Run Code Online (Sandbox Code Playgroud)

c c++ arrays initialization c++11

2
推荐指数
1
解决办法
3188
查看次数

自定义数据类型的Haskell show定义对前导引号的使用不一致

这是我正在处理的代码的简化版本

data ArithExp = Con Int
          | Add ArithExp ArithExp

instance Show ArithExp where
          show (Con i)     = show i
          show (Add e1 e2) = show "( " ++ show e1 ++ " + " ++ show e2 ++ " )"
Run Code Online (Sandbox Code Playgroud)

所以,如果我运行命令

Add (Con 6) (Con 0)
Run Code Online (Sandbox Code Playgroud)

我想要的输出是:

( 6 + 0 )
Run Code Online (Sandbox Code Playgroud)

但上面的代码打印:

"( "6 + 0 )
Run Code Online (Sandbox Code Playgroud)

据我所知,show函数将第一个字符串中的引号打印为字符,然后在后面的串联中正确使用它们.这种行为对我来说似乎很不一致.任何有助于我获得正确输出的见解都将非常感激.提前致谢!

haskell show

2
推荐指数
1
解决办法
167
查看次数

c ++如何通过引用将迭代器指针传递给期望对象的函数

所以在我的正文代码中,我创建了一个迭代器来处理指向Point对象的指针列表,我需要能够将该指针传递给set_point_one函数.

list<Point*>::iterator it = on.begin();
l->set_point_one(*it);
Run Code Online (Sandbox Code Playgroud)

set_point_one函数重载如下:

void set_point_one(const double x, const double y, const double z) { one_.set_xyz(x, y, z); }
void set_point_one(Point &p) { one_.set_xyz(p.get_x(), p.get_y(), p.get_z()); } //trying to get it to use this one
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,我收到错误:

./facet.cc:79:20: error: no matching member function for call to 'set_point_one'
            l->set_point_one(*it);                             //set both end points of the line to the point
            ~~~^~~~~~~~~~~~~
./line.cc:21:10: note: candidate function not viable: no known conversion from 'value_type' (aka 'Point *') to 'Point &' for 1st …
Run Code Online (Sandbox Code Playgroud)

c++ pointers iterator pass-by-reference

2
推荐指数
1
解决办法
4157
查看次数

C++中交叉依赖类的最佳实践

我有两个相互依赖的类:

// model.h
#include "facet.h"
class Model {
    ...
    std::map<int, std::vector<Facet*> > enqueue_list_;
}

// facet.h
#include "model.h"
class Facet {
    ...
    Model *parent_;
}
Run Code Online (Sandbox Code Playgroud)

编译时,编译器显然非常沮丧.我用这样的前向类声明修复了它:

// model.h
#include "facet.h"
class Facet;
class Model {
    ...
    std::map<int, std::vector<Facet*> > enqueue_list_;
}

// facet.h
#include "model.h"
class Model;
class Facet {
    ...
    Model *parent_;
}
Run Code Online (Sandbox Code Playgroud)

但我不喜欢这样做.这对我来说似乎很麻烦,很难维护.我认为通过使用头文件开始解决这类问题.有没有更好的方法来解决我错过的问题?我不想在其他类头文件中转发声明类.我觉得我在这里缺少一些重要的东西.如果我仍然遇到交叉依赖性投诉,那么头文件的确切意义何在?
提前谢谢,
马克斯

编辑

感谢您的快速回复.我接受了建议并删除了头文件中的包含,并完全切换到转发声明.我是正确的假设我仍然需要实际包含标头,如果类具有类似直接的类分配:

// facet.h
#include "point.h"
class Facet {
    ...
  private:
    Point normal_;
}
Run Code Online (Sandbox Code Playgroud)

在尝试使用前向声明时,我遇到了错误.这确实是我必须要做的情况#include吗?

c++ header class circular-dependency forward-declaration

2
推荐指数
1
解决办法
776
查看次数

Bash 循环遍历元素列表

我有一个我使用的脚本,看起来像这样

cd ~/.vim/bundle/supertab
git pull
cd ~/.vim/bundle/syntastic
git pull
cd ~/.vim/bundle/vim-alternate
git pull
cd ~/.vim/bundle/vim-easymotion
git pull
cd ~/.vim/bundle/vim-matchit
git pull
cd ~/.vim/bundle/vim-togglemouse
git pull
Run Code Online (Sandbox Code Playgroud)

我想更新它,以便它循环遍历列表,这样我就可以得到一些改进的输出,而无需重复的显式代码。我非常不擅长 shell 脚本编写,想知道是否有可能有一个 bash 脚本,如果它是用 C 完成的,那么它可以运行这样的东西

vector<string> v{"supertab" , "syntastic", "vim-alternate", 
                 "vim-easymotion", "vim-matchit", "vim-togglemouse"};
for (string it : v) {
    system("cd ~/.vim/bundle/" + it);
    cout << it << ": ";
    system("git pull");
}
Run Code Online (Sandbox Code Playgroud)

bash loops list

2
推荐指数
1
解决办法
7953
查看次数

C++ ternary operator with function calls

I'm trying to clean up some code with ternary operators and I'm running into some compiler errors i can't make sense of.

The code I had before looks like this and runs fine.

if(!inFile.good())
     throw -2;
getline(inFile, inLine);
Run Code Online (Sandbox Code Playgroud)

And I'm trying to clean it up using this code instead.

(inFile.good()) ? getline(inFile, inLine) : throw -2;
Run Code Online (Sandbox Code Playgroud)

But I'm getting the following errors.

g++ -w -o test orange_test.cpp
In file included from orange_test.cpp:4:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:39:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/streambuf:558:31: error: base …
Run Code Online (Sandbox Code Playgroud)

c++ std ternary-operator

0
推荐指数
1
解决办法
3179
查看次数