我正在将命令行转换为python字符串.命令行是:
../src/clus -INFILE=../input/tua40.sq -OUTPUT=OUT
Run Code Online (Sandbox Code Playgroud)
python语句是:
c_dir = '~/prj/clus/'
c_bin = c_dir + 'src/clus'
c_data = c_dir + 'input/tua40.sq'
c = LiveProcess()
c.executable = c_bin
c.cwd = c_dir
c.cmd = [c.executable] + ['-INFILE=', 'c_data, '-OUTPUT=OUT']
Run Code Online (Sandbox Code Playgroud)
问题是c.cmd最后的样子
~/prj/clus/src/clus -INFILE= ~/prj/clus/input/tua40.sq ...
Run Code Online (Sandbox Code Playgroud)
并非'='后面有一个"空格",导致程序报告错误.
如何将'='连接到路径?
我想将具有此模式的所有文件重命名-512-到-256-文件夹中?我怎么能用mv做到这一点?我知道我必须使用xargs并管道它,find但不知道如何告诉xargs
find . -name *-512-*
Run Code Online (Sandbox Code Playgroud)
和
xargs mv ?????
Run Code Online (Sandbox Code Playgroud) 我已经定义了unordered_map这样的
struct pht {
pht(int t, vector<bool> pat)
: tag(t), pattern(32) {}
private:
int tag;
vector<bool> pattern;
};
unordered_map< pair<int, int>, pht > predictor;
int main()
{
int pc, addr, offset, tag;
vector<bool> pat;
srand(time(0));
tag = 1000; pc = 100; offset = 10;
for ( int i = 0; i < 32; i++ )
pat.push_back( rand() % 2 );
predictor.insert(make_pair( make_pair(pc, offset), pht(tag, pat) ) );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是我收到此错误:
(更新)
error C2440: 'type cast' : cannot …Run Code Online (Sandbox Code Playgroud) isInstruction()我的代码(不是我的)中有一个函数,用于设置和获取成员没有问题.现在我为了类似的目的添加了我自己的功能state().像这样:
struct foo {
bool & isInstruction() {
return isInst; // no problem
}
int & state() {
return state; //ERROR
}
private:
bool isInst;
int state;
};
Run Code Online (Sandbox Code Playgroud)
我对第一个函数没有问题.但是对于第二个,我得到了
error: invalid initialization of reference of type ‘int&’ from expression of type
‘<unresolved overloaded function type>’
Run Code Online (Sandbox Code Playgroud)
那么问题是这两个函数之间的区别是什么.我错过了什么吗?
我有一个.cc文件,使用iostream和malloc.我怎么编译呢?使用g++,它说
error: 'malloc' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
使用gcc,它说
fatal error: iostream: No such file or directory
Run Code Online (Sandbox Code Playgroud)
源代码位于http://sequitur.info/sequitur_simple.cc
UPDATE
我改变malloc了new并且去free了delete.我仍然遇到很多错误.例如
/usr/include/c++/4.6/new:103:14: error: initializing argument 2 of âvoid* operator new(std::size_t, void*)â [-fpermissive]
Run Code Online (Sandbox Code Playgroud) 我想从http://pages.cs.wisc.edu/~travitch/pthreads_primer.html(Mutex部分)编译示例pthread代码.当我运行此命令时:
gcc -pedantic -Wall -o theaded_program pth.c -lpthread
Run Code Online (Sandbox Code Playgroud)
在链接中说明,我收到此错误
pth.c:45:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
/tmp/ccajksBv.o: In function `opponent':
pth.c:(.text+0x4a): undefined reference to `tan'
/tmp/ccajksBv.o: In function `main':
pth.c:(.text+0x131): undefined reference to `tan'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
但是#include <math.h>代码中有!! gcc版本是4.6
使用kcachegrind并在调试模式下运行代码,我发现我的程序的瓶颈是两个向量进行比较的点.
if (v1 == v2) {
// DO
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能提高效率?这是否更好
if (v1[0] == v2[0]) {
if (v1 == v2) {
// DO
}
}
Run Code Online (Sandbox Code Playgroud)
第一行将过滤一些无用的比较.
在此之前我尝试过
if (!v2.empty())
if (v1 == v2)
// DO
Run Code Online (Sandbox Code Playgroud)
但是我发现他们几乎总是不空.因此还包括空()的额外时间.
我不得不说矢量的大小很小.2~4个元素.在极少数情况下,它们将延伸到10.
更新: 感谢Mats Petersson,似乎通过在优化模式下进行编译,可以提高性能.
是否有可能在断言错误上写一条消息?
例如,使用#include <assert.h>,我只能写:
void foo(int a, int b) {
assert (a != b);
}
Run Code Online (Sandbox Code Playgroud)
然而,在一个错误我想看到的价值a和b.我怎样才能做到这一点?
我写了一个代码,试图在向量中找到重复.如果重复,它会将位置添加到列表中.例如,序列100 110 90 100 140 90 100将是2D矢量.第一维包含唯一的字母(或数字),并且重复列表作为第二维附加.所以结果看起来像
100 -> [0 3 6]
110 -> [1]
90 -> [2 5]
140 -> [4]
Run Code Online (Sandbox Code Playgroud)
代码非常简单
typedef unsigned long long int ulong;
typedef std::vector<ulong> aVector;
struct entry {
entry( ulong a, ulong t ) {
addr = a;
time.push_back(t);
}
ulong addr;
aVector time;
};
// vec contains original data
// theVec is the output vector
void compress( aVector &vec, std::vector< entry > &theVec )
{
aVector::iterator it = vec.begin();
aVector::iterator …Run Code Online (Sandbox Code Playgroud) 以下代码,简单地说
1)从命令行参数中获取输入文件名,比如in.txt
2)将文件名附加到"cdf_"
3)打开一个名为cdf_in.txt的文件
4)简单地从(每行中的一个数字)读取每一行并将其发送到输出文件.
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main(int argc, char* argv[])
{
char *ben = argv[1]; // example: in.txt
ifstream fin (ben);
char res[30];
char *o1 = "cdf_";
strcat(res, o1);
strcat(res, ben);
ofstream fout (res, std::ofstream::out); // will be cdf_in.txt
cout << res << endl;
uint64_t num; uint64_t sum = 0;
while (fin >> num) {
fout << num << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
通过运行程序而不进行任何优化,它可以正常运行.但是,通过指定-O3,它无法创建输出文件.为什么???
$ g++ -o cdf …Run Code Online (Sandbox Code Playgroud)