错误无法在赋值中将"std::string {aka std::basic_string<char>}"转换为"char" - C++
Error cannot convert 'std::string {aka std::basic_string<char>}' to 'char' in assignment - C++
所以我在代码行中得到了上面提到的错误:"women[count_wc]=(temp(;"[Error]无法在赋值-C++中将"std::string{aka std::basic_string}"转换为"char">
它在被调用的函数内部。
此外在实际调用函数的地方发现了另一个错误。处的错误"get_comp_women(women,MAX_W,array,ROW(;"是[Error]无法将"(std::string*((&women("从"std::string*{aka std::basic_string*}"转换为"std:string{akastd::asic_string}">
const int MAX_W = 18;
const int MAX_T = 18;
const int MAX_E = 14;
const int ROW = 89;
using namespace std;
struct data
{
string name;
string event;
};
void get_comp_women(string women, int MAX_W, data array[], int ROW)
{
int count_wc = 0;
int count_wn = 0;
int event_occ = 0;
string temp;
temp = (array[0].name);
event_occ = (ROW + MAX_W);
for (int i = 1; i < event_occ; i++)
{
if (temp == array[count_wn].name)
{
women[count_wc] = (temp);
count_wn++;
}
else
{
temp = array[count_wn].name;
count_wc++;
}
}
int main()
{
string women[MAX_W];
data array[ROW];
get_comp_women(women, MAX_W, array, ROW);
}
您的函数接受women
作为std::string
,而您需要一个数组,因此,在函数中women[count_wc]
的意思是"字符串中的字符",而不是"字符串数组中的字符串">
women[count_wc] = (temp);
____________/ ____/
^ ^-----std::string
^--- one character in the string
您需要更改函数签名,使其接受std::string[]
而不是std::string
:
void get_comp_women(string women[], int MAX_W, data array[], int ROW)
您得到的第二个错误是不言自明的,也就是说(试图将数组传递到等待字符串的函数中(。
void get_comp_women(string women, int MAX_W, data array[], int ROW)
应该成为
void get_comp_women(string women[], int MAX_W, data array[], int ROW)
函数的调用及其内部的逻辑都需要一个数组。
相关文章:
- 使用char类型将decimal转换为string,将string转换为decimal
- std::string 构造函数如何处理固定大小的 char[]?
- C++:将模板类型 char 转换为 std::string
- 从 std::string 到 std::array<char,size> 的 memcopy 额外数据是否是一种未定义的行为?
- "No suitable conversion function from 'std::string' to 'const char *' exists"
- 将"std::string {aka std::basic_string}"赋值中的不兼容类型<char>
- 错误:为"运算符 std::string {aka std::__cxx11::basic_string}"指定的返回类型<char>
- 为什么std::string没有(显式)const char*强制转换
- 将 std::string 转换为 const char* 用于 printf 消耗
- 我可以使用istream_iterator将<char>一些 istream 内容复制到 std::string 中吗?
- 让 'std::vector<unsigned char>' 从 'std::string' 中窃取内存
- 错误:请求从"Mstream"转换为非标量类型"std::string {aka std::basic_string<char>}"
- C++:使用委托构造函数时选择"const char *"与"std::string&qu
- 从内部使用静态 std::string 的函数返回 const char * 是否安全?
- 从类方法返回 "const char*" 作为 std::string&
- 如何将 std::string 赋回作为 <char>void* 指针传递的 std::vector.data()?
- 将 'hana::string' 转换为 'constexpr const char (&)[]'
- C++中的"string()+char"
- Picky STD :: String Char Array构造函数
- "std::string + char"表达式会创建另一个 std::string 吗?