小编Dou*_* T.的帖子

在书写行之间创建空间

我目前正在创建一个函数,该函数从其他函数读取数据并将其写入桌面上的文本文件.

def outputResults(filename):
"""This function serves to output and write the results from analyzeGenome.py to a text file \
   Input: filename of output file, dictionary of codon frequencies, dictionary of codon counts \
        GC-content, FASTA header, & sequence length

   Output: Text file containing all the above """

outString = "Header = %s" %header
filename.write(outString)

outString2 = "Sequence Length = %.3F MB" % length
filename.write(outString2)
Run Code Online (Sandbox Code Playgroud)

当我这样做时,python在文本文件中一个接一个地打印行.如何打印到下一行并在行之间添加空格?

python io file-io

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

让两个dll共享一个静态库会有什么陷阱?

假设你有两个dll

Dll A和Dll B.

它们都静态链接到静态库(即.lib文件).我们称之为图书馆L.

我知道L完全链接到A和B,分别有效地创建LA和LB. 但是,当来自洛杉矶的对象O从A传递到B时会发生什么?我假设在A LA代码中执行,而在B LB代码中执行,因为这是如何发生链接的.如果在A中创建O,卸载A,然后在B中使用O,会发生什么不好的事情?

c++ windows dll

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

c ++ vector; remove_if只删除一个值?

我应该实现一个从容器中删除一系列值的函数.所以

eraseRange(v, 1.5, 24);
Run Code Online (Sandbox Code Playgroud)

例如,从容器v中删除大于1.5且小于24的任何值.并且我的函数适用于列表,我在其中使用:

container.erase(remove_if(container.begin(), container.end(), rg));
Run Code Online (Sandbox Code Playgroud)

rg检查它是否在范围内(该部分的实现不是问题,所以我不打算详细说明).

但是,当为向量调用eraseRange并使用类似的方法擦除值时,只有第一个值被擦除.所以,如果我有一个数字从1到10的向量,我打电话给:

eraseRange(v, 3, 7);
Run Code Online (Sandbox Code Playgroud)

只有3个被删除.

现在这通常不会成为问题,我只想使用迭代器来检查值.除了这个特定的练习,明确禁止/ while/do循环...

所以问题似乎是具有随机访问迭代器的容器.而且我不确定如何实施替代方案.救命?

c++ stl erase remove-if

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

拥有动态对象的std ::数组是否安全?

std::array例如std::array<std::string, 3>,拥有一个动态对象并调整内容(字符串)的大小是否安全?(因为有一个原始的C字符串数组可能会有问题)

c++ arrays memory-management stl c++11

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

Win32消息泵与MFC消息映射,哪个更快?C++

不是从易用性,而是从性能的角度来看.MFC消息映射比典型的消息泵更快吗?

c++ winapi mfc

0
推荐指数
2
解决办法
2573
查看次数

10个字符ID,全局和本地唯一

我需要生成一个10个字符的唯一ID(SIP/VOIP人员需要知道它是P-Charging-Vector头中的param icid值).每个字符应为26个ASCII字母之一(区分大小写),10个ASCII数字之一或连字符减号.

它必须是"全局唯一的(在生成id的机器之外)"并且足够"本地唯一(在生成id的机器内)",并且所有需要打包成10个字符,p!

这是我的看法.我是第一个编码'必须'编码全局唯一本地IP地址到base-63(它是一个无符号长整数,编码后将占用1-6个字符)然后尽可能多的当前时间戳(其一个time_t/long long int,编码后将占用9-4个字符,具体取决于编码的ip地址占用的空间大小.

我还在时间戳中添加了循环计数'i',以便在一秒钟内多次调用该函数时保留唯一性.

这是否足以在全球和本地独特,还是有另一种更好的方法?

拉夫

#include <stdio.h>
#include <string.h>
#include <sys/time.h>

//base-63 character set
static char set[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-";

// b63() returns the next vacant location in char array x
int b63(long long longlong,char *x,int index){
    if(index > 9)
        return index+1;

    //printf("index=%d,longlong=%lld,longlong%63=%lld\n",index,longlong,longlong%63);
    if(longlong < 63){
        x[index] = set[longlong];
        return index+1;
    }  

    x[index] = set[longlong%63];
    return b63(longlong/63,x,index+1);
}

int main(){
    char x[11],y[11] = {0}; /* '\0' is taken care of here */

    //let's generate 10 million ids
    for(int i=0; …
Run Code Online (Sandbox Code Playgroud)

c c++ linux x86-64 sip

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

C++ Overload =运算符

我不确定为什么在尝试重载=运算符时出现以下错误

error: passing ‘const MyCircle’ as ‘this’ argument of ‘double MyCircle::getRadius()’ discards qualifiers|
Run Code Online (Sandbox Code Playgroud)

码:

#include <iostream>

#define PI 3.14

using namespace std;


class MyCircle
{
  public:
    MyCircle();
    MyCircle(int r);
    MyCircle(const MyCircle& c);
    void setRadius(double r);
    double getRadius();
    double getArea();
    static void increaseInstanceCount();
    static int getInstanceCount();
    MyCircle operator=(const MyCircle &);

  private:
    double radius;
    static int instanceCount;
};

int MyCircle::instanceCount = 0;

/**
1. A default constructor, that sets the radius to 0
**/
MyCircle::MyCircle()
{
    radius = 0.0;
    increaseInstanceCount();
}

/** …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors const operator-overloading

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

从stringstream获取所有内容

我已将som信息放入stringstream ss:

stringstream ss (stringstream::in | stringstream::out);
ss<<"abc 456 ";
ss<<123
Run Code Online (Sandbox Code Playgroud)

然后我决定将字符串内容检索到字符串g:

std::string s;
std::string g;

for (int n=0; n<c; n++)
{
ss >> s;
g=g+s;
}
cout << g <<endl;
Run Code Online (Sandbox Code Playgroud)

出于这个原因,我需要知道对ss进行了多少次放置.怎么知道?检索字符串信息的方法可能不是很聪明 - 然后给你自己的方式.

c++ stringstream visual-c++

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