小编Cor*_*mer的帖子

如何在qt creator中将QString转换为int

我已经看到了关于同一个问题的一个答案但是当我用我的问题尝试它时会感到困惑.

这是我的字符串,

bit_rate = "bitrate: 2334 kb/s"
Run Code Online (Sandbox Code Playgroud)

我需要2334从这个字符串中获取并将其分配给一个整数变量..这在qt creator中是如何实现的.我试过了toInt(),但它总是给出0答案.

c++ string int qt

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

引用对象datamember时使用变量

我有点困在这里.所以假设我有一个字段列表(在DB表的上下文中):

list = ['title', 'description', 'name']
Run Code Online (Sandbox Code Playgroud)

这些字段存在于数据库表Foo中.

所以这是我的问题......

foo = Foo()
for i in list:
    foo.i = "value"
foo.save()
Run Code Online (Sandbox Code Playgroud)

问题是解释器正在寻找一个被调用的数据库'i',并且没有事先映射它的值(这可能是标题或描述).有没有办法解决?

谢谢!

python django

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

C++中的全局枚举

好吧我想要将地形枚举定义为

enum terrain {MOUNTAIN, GRASS};
Run Code Online (Sandbox Code Playgroud)

或者其他的东西.

我如何使这个枚举在我的项目中的所有类中定义?

c++ enums

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

使用variadic-template函数计算多个值的平均值

我正在尝试编写一个函数来确定任意数量的参数的平均值,所有这些参数都具有相同的类型.出于学习目的,我试图使用可变参数模板函数来做到这一点.

这是我到目前为止:

template<typename T, class ... Args>
T Mean(Args ... args)
{
    int numArgs = sizeof...(args);
    if (numArgs == 0)
        return T();           // If there are no arguments, just return the default value of that type

    T total;
    for (auto value : args...)
    {
        total += value;
    }

    return total / numArgs;   // Simple arithmetic average (sum divided by total)
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译它(使用MS Visual Studio 2013)时,我收到以下编译错误:

error C3520: 'args' : parameter pack must be expanded in this context (test.cpp)
Run Code Online (Sandbox Code Playgroud)

我该如何正确"解包" args …

c++ average variadic-templates c++11

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

我们不能混合使用g ++和clang ++编译的对象(或库)?至少在Mac上?

功能如

MyFunction(std::string) 
Run Code Online (Sandbox Code Playgroud)

在Mac上用g ++编译为:

__Z6MyFuncSs
Run Code Online (Sandbox Code Playgroud)

解构为:

MyFunction(std::string)
Run Code Online (Sandbox Code Playgroud)

用clang ++编译时,它是:

__Z6MyFuncNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE
Run Code Online (Sandbox Code Playgroud)

解构为:

MyFunc(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)
Run Code Online (Sandbox Code Playgroud)

在Linux上没有相同的问题
任何人都知道为什么?

c++ compilation g++ clang++

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

如何创建另一个类struc的向量?(C++ 11)

我搜索了我的问题的解决方案,但没有找到,所以我在这里问.

A有一个名为equacao的公共结构的类,我想在main.cpp或另一个类中创建一个equacao向量.但它给出了一个错误:

error: 'equacao' does not name a type
Run Code Online (Sandbox Code Playgroud)

可以帮忙吗?

坦克.

class algoritimoGenetico
{    
public:

    struct termo
    {
        std::uint_fast16_t atrazo : 6;
        std::uint_fast16_t colunaVariavel : 10;
        float expoente;
    };
    struct regresor
    {
        std::vector<termo> termos;
        std::uint_fast16_t coeficiente;
        bool divisor;
    };
    struct equacao
    {
        std::vector<regresor> regresores;
        std::uint_fast16_t maiorAtrazo;
        float aptidao;
        float erroQuadratico;

    };
Run Code Online (Sandbox Code Playgroud)

在main.cpp我尝试:

 algoritimoGenetico AG;

 std::vector<std::vector< AG.equacao > >  mat(40000, std::vector<AG.equacao> (7));
Run Code Online (Sandbox Code Playgroud)

c++ struct class vector

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

在C ++中使用自定义结构作为map的索引时,“二进制表达式的无效操作数”

代码:

struct Tag {
    std::string left_tag, right_tag;
};
Run Code Online (Sandbox Code Playgroud)

当我尝试使用时this->_tags[__tag] = true;,出现错误:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__functional_base:63:21: error: invalid operands to binary expression ('const Tag' and 'const Tag')
        {return __x < __y;}
                ~~~ ^ ~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/map:1207:17: note: in instantiation of member function 'std::__1::less<Tag>::operator()' requested here
            if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first))
                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/map:1376:36: note: in instantiation of member function 'std::__1::map<Tag, bool, std::__1::less<Tag>, std::__1::allocator<std::__1::pair<const Tag, bool> > >::__find_equal_key' requested here
    __node_base_pointer& __child = __find_equal_key(__parent, __k);
                                   ^
/Users/xxx/GitHubWorking/MarkupUtils/Syntax.h:69:20: note: in instantiation of member function 'std::__1::map<Tag, bool, std::__1::less<Tag>, std::__1::allocator<std::__1::pair<const …
Run Code Online (Sandbox Code Playgroud)

c++ sorting stl

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

dict对象不可调用

这是我的python程序,它与mongodb*建立连接

import pymongo
from pymongo import MongoClient
connection = MongoClient('localhost', 27017)
db = connection.test
names = db.names
item =names.find_one()
print item('name')
Run Code Online (Sandbox Code Playgroud)

而且,我收到了这个错误

C:\Users\hpg6\Desktop>python mycon.py
Traceback (most recent call last):
  File "mycon.py", line 15, in <module>
    print (item('name'))
TypeError: 'dict' object is not callable
Run Code Online (Sandbox Code Playgroud)

python mongodb bottle

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

在 C++ 中创建目录

我正在用 DirectX 和 C++ 制作一个简单的游戏。但我想在 Documents 中为设置等创建一个目录。

但我不知道我需要怎么做?

有人能帮我吗?

c++ filesystems directory file-io visual-c++

2
推荐指数
3
解决办法
4万
查看次数

连接列表和int

我正在尝试学习python,我遇到了快速排序算法.这是我到目前为止用例子列表写的: [3,1,2,2,1,3,6,7,5,4,8]

def quick(self):
    first = self.lst[0]
    l1 = []
    l2 = []
    for item in self.lst[1:]:
        if item <= first:
            l1.append(item)
            print('this is l1:',l1)
        else:
            l2.append(item)
            print('this is l2:', l2)

        return _____
Run Code Online (Sandbox Code Playgroud)

我正在尝试这样做self.lst = l1 + first + l2,但是当我这样做时,我得到一个错误,指出:

self.lst = l1 + first + l2
builtins.TypeError: can only concatenate list (not "int") to list
Run Code Online (Sandbox Code Playgroud)

我只是想让第一遍正确,也许实现一个while True until l1 = []或者什么.

  1. 如何将l1,first和l2连接在一起?
  2. 在第一步之后,你们建议我做什么?

非常感谢你!

python sorting list quicksort

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