小编Igo*_*gor的帖子

降序的最佳方法是什么?

所有,

std :: sort()将按升序排序.有一种简单,方便,快捷的降序方式吗?

谢谢.

c++ sorting stl

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

如何在python中进行循环

所有,

我有以下列表:

["abc","def","ghi"]

我需要从中得到一个字符串:

"ABC,DEF,GHI"

第一个和第二个元素之间有一个逗号,但不在字符串的末尾.

不幸的是,Python没有像以下那样的结构:

std::string str;
for( int i = 0; i < 3; i++ )
{
    str += list[i];
    if( i != 2 )
        str += ",";
}
Run Code Online (Sandbox Code Playgroud)

我怎么用Python做的?

python string for-loop list

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

增加迭代器标准映射

所有,

std::map<int, std::string> addressee;
std::map<int, std::string>::iterator it1, it2;

for( it1 = addressee.begin(); it1 != addressee().end(); it1++ )
{
    bool found = false;
    for( it2 = it1 + 1; it2 != addressee.end() && !found; it2++ )
    {
       if( it1->second == it1->second )
       {
           printf( "Multiple occurences of addressees found" );
           found = true;
       }
    }
}
Run Code Online (Sandbox Code Playgroud)

gcc吐出错误:不匹配operator +.

这段代码是我正在尝试做的简化版本.我想我可以使用std :: advance(),但它似乎只是浪费函数调用.

有更好的解决方案吗?

c++ dictionary iterator

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

如何正确删除这些指针?

这是我的分配:

for (int i = 0; i < numCols; i++)
{
    columnNameLen = new SQLSMALLINT *[numCols];
    columnDataType = new SQLSMALLINT *[numCols];
    columnDataSize = new SQLULEN *[numCols];
    columnDataDigits = new SQLSMALLINT *[numCols];
    columnDataNullable = new SQLSMALLINT *[numCols];
    columnData = new SQLWCHAR *[numCols];
    columnDataLen = new SQLLEN *[numCols];
    columnName = new SQLWCHAR *[numCols];
}

for (int i = 0; i < numCols; i++)
{
    columnNameLen[i] = new SQLSMALLINT;
    columnDataType[i] = new SQLSMALLINT;
    columnDataSize[i] = new SQLULEN;
    columnDataDigits[i] = new SQLSMALLINT;
    columnDataNullable[i] = …
Run Code Online (Sandbox Code Playgroud)

c++ pointers smart-pointers c++11

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

引用已删除的析构函数

我有以下代码:

struct Foo
{
    int type;
    union
    {
        int intValue;
        double doubleValue;
        std::wstring stringValue;
    } value;
};
Run Code Online (Sandbox Code Playgroud)

然后在cpp文件中我有:

std::vector<Foo> row;
some_class_object->func( row );
Run Code Online (Sandbox Code Playgroud)

我得到了:

error C2280: 'void *Foo::__delDtor(unsigned int)': attempting to reference a deleted function 
Run Code Online (Sandbox Code Playgroud)

这里有什么问题?

编辑:

所以我添加了这个析构函数:

~Foo()
{
    if( type ==3 )
        value.stringValue.~std::wstring();
}
Run Code Online (Sandbox Code Playgroud)

我得到了一个错误:

error C2061: syntax error: identifier 'wstring'.
Run Code Online (Sandbox Code Playgroud)

在这种情况下,显然 std::string 与 std::wstring 很重要......

不知道。

编辑2:

我现在得到:

 error C2280: 'Foo::<unnamed-type-value>::~<unnamed-type-value>(void)': attempting to reference a deleted function
Run Code Online (Sandbox Code Playgroud)

c++ c++11

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

我可以在这里使用模板吗?

我有以下代码:

int CreatePropertiesDialog(int type, void *object)
{
    if( type == 1 )
    {
        ClassA *a = static_cast<ClassA *>( object );
        // build the properties dialog
    }
    if( type == 2 )
    {
        ClassB *b = static_cast<ClassB *>( object );
        // build the properties dialog
    }
    // display the properties dialog
}
Run Code Online (Sandbox Code Playgroud)

但是,使用void*类型听起来非常难看.

可以使用模板改进此代码吗?或者其他一些手段?

c++ c++11

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

标签 统计

c++ ×5

c++11 ×3

dictionary ×1

for-loop ×1

iterator ×1

list ×1

pointers ×1

python ×1

smart-pointers ×1

sorting ×1

stl ×1

string ×1