我有一个期望字符串的函数,我想将const char*连接到要返回的字符串.
以下是帮助说明此方案的示例代码:
void TMain::SomeMethod(std::vector<std::string>* p)
{
p->push_back(TAnotherClass::Cchar1 + "/" + TAnotherClass::Cchar2);
}
Run Code Online (Sandbox Code Playgroud)
这是另一类来自:
class TAnotherClass
{
public:
static const char * Cchar1;
static const char * Cchar2;
};
const char * TAnotherClass::Cchar1 = "Home";
const char * TAnotherClass::Cchar2 = "user";
Run Code Online (Sandbox Code Playgroud)
我得到以下错误:类型'const char*'和'const char*'的无效操作数到二元运算符+
为什么这无效?请帮忙
我遇到了一个问题,想知道是否有人可以帮助我.
在我的一个班级(例如class1)中,我有一个
typedef boost::shared_ptr <class-one-object>
typedef std::vector<class-one-object>
在另一个类(例如class2)中,我需要再次创建一个向量,以便迭代这个
class-one-object
所以我尝试了以下内容
class1::ImportTableObject& table = configPtr->getTable();
std::vector<class1::class-one-object>::const_iterator* iter = table.begin();
Run Code Online (Sandbox Code Playgroud)
这引发了以下编译错误:
cannot convret `__gnu_cxx::__normal_iterator<boost::shared_ptr<class1::class-one-object>*, std::vector<boost::shared_ptr<class1::class-one-object>,
std::alloctor<boost::shared_ptr<class1::class-one-object> > > to '__gnu_cxx::__normal_iterator<const class1::class-one-object*, std::vector<class1::class-one-object>
Run Code Online (Sandbox Code Playgroud)
等等
有人可以帮我吗?
先感谢您
我试图提取两个(int32_t)值,并将它们放在一个char数组中.
int32_t version = getVersion();
if (version < 0)
{
return;
}
else
{
//first part of number needs to be shifted right
int32_t major = (((version) >>16) & 0xFFFF);
int32_t minor = ((version) & 0xFFFF);
// need to concatenate these two values, and place a "." between them
setVersion(...);//requires a char array, should for example be "1.1"
}
Run Code Online (Sandbox Code Playgroud)
谁能给我任何关于最佳方法的建议呢?请不要使用std :: strings.我更喜欢char数组.
提前致谢