小编Igo*_*Oks的帖子

在标准地图元素上调用函数而不先插入它

以下代码可以吗?

class A
{
  public:
    A();
    void foo();
};

map<int,A> m;
m[0].foo();
Run Code Online (Sandbox Code Playgroud)

或者我必须执行以下操作:

map<int,A> m;
m[0] = A();
m[0].foo();
Run Code Online (Sandbox Code Playgroud)

而且,我可以这样做:

map<int,A> m;
A a = m[5];
Run Code Online (Sandbox Code Playgroud)

如何通过引用访问:

void foo(A & a);
map<int,A> m;
foo(m[5]);
Run Code Online (Sandbox Code Playgroud)

c++ std map

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

这个警告信息是什么意思?

Product.cpp:34:警告:'QTextStream&endl(QTextStream&)'的地址将始终评估为'true'

Product.cpp:在成员函数'void Product :: setProductToSold()'中:

Product.cpp:45:警告:'QTextStream&endl(QTextStream&)'的地址将始终评估为'true'

#include <string>
#include <iostream>
#include <time.h>
using std::string;
using std::cout;

#include "Product.h"

Product::Product()
{
    seller = "";
    itemName = "";
    price = 0.00;
    min = 0.00;
    buyingPrice = 0.00;
    time = 0;
    description = "";
    highestBidder = "None";
    currentBid = 0.00;

    timer = new QTimer( this );
    connect( timer, SIGNAL(timeout()), this, SLOT(setProductToSold()) );
}

void Product::startTimer()
{
Line 34:    cout << " Timer Started " << endl;
    timer->start( 2000, TRUE ); // 2 seconds …
Run Code Online (Sandbox Code Playgroud)

c++ qt

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

将字节数组转换为字符串而不解释字节?

我有一个PDU编码短信的GSM日期/时间戳,它的格式是这样的

\ X90,\ X21,\ X51,\ X91,\ X40,\ X33

格式yy,mm,dd,hh,mm,ss

我已经将它们从二进制文件读入字节数组.我想将它们转换为字符串,但没有做任何解码我想最终得到一个包含902151914033的字符串.然后我需要反转字符串中的每2个字符.

谁能给我一些指示?非常感谢

python decode bytearray

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

如何证明以下算法的正确性?

我需要证明以下算法正常工作,我知道归纳,但不知道如何在这里使用它?如果知道算法的复杂性,它是多么最优,我会很高兴吗?什么是运行时间?请帮助我

#include <cstdlib>
#include <iostream>
#define c 2
//we should take c   more ot equal  then 2
using namespace std;
int multiply(int y,int z){
      // product yz
    if(z==0) return 0;
    return (multiply(c*y,int(z/c))+y*(z %c));
}

int main(int argc, char *argv[])
{
    int y=5;
    int z=7;
    cout<<multiply(y,z)<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

谢谢

c++ algorithm

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

标签 统计

c++ ×3

algorithm ×1

bytearray ×1

decode ×1

map ×1

python ×1

qt ×1

std ×1