C2664 :当我使用 str.append(str[i]) 时,发生错误
C2664 :when I use str.append(str[i]),error happening
string s1;
string s2;
getline(cin >> fixed, s);
for (int j = 0; j < s.length(); j++)
{
if ((j & 1) == 0)
{
s1.append(s[j]);//the type of s[j] is char,but the error still
//happening,
cout << tmp << endl;
}
else
{
s2.append(s[j]);
}
}
cout << s1 << " " << s2 << endl;
C2664"std::basic_string,std::分配器> &std::basic_string,std::分配器>::append(const std::basic_string,std::allocator> &(":无法将 elem 1 形式的 "char" 转换为 "std::initializer_list<_Elem>">
没有需要单个char
的append()
过载。看看这里:
http://en.cppreference.com/w/cpp/string/basic_string/append
只有一个重载需要单个char
:
basic_string& append( size_type count, CharT ch );
因此,您可以使用它:
s1.append(1, s[j]);
或者,改用operator+=
:
s1 += s[j];
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 这是 boost::filesystem 中的错误吗?为什么 boost::filesystem::p ath::str
- 如何修复此错误? "Method 'str' could not be resolved"
- C2664 :当我使用 str.append(str[i]) 时,发生错误
- Str.find成员函数错误
- if(str == NULL || str.length() == 0)获取错误