所有,
我有以下列表:
["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做的?
所有,
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(),但它似乎只是浪费函数调用.
有更好的解决方案吗?
这是我的分配:
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) 我有以下代码:
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) 我有以下代码:
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*类型听起来非常难看.
可以使用模板改进此代码吗?或者其他一些手段?