error C2440: '=' : cannot convert from 'std::string' to 'char'

I'm sorry if this is a stupid question... I just started taking a course to learn C++ and don't have any previous experience, so be gentle :) I keep getting this error message (error C2440: '=' : cannot convert from 'std::string' to 'char') to my code pasted below. I've added ** to the two lines the error is referring to... feel free to "treat me like i'm 5" ;)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 #include <iostream>
#include <string>

using namespace std;

string airline_name[6], destination[6], swapping, air_duplicate, des_duplicate, index;
char reply, x;

void load_array_data()
{
	cout<< "ABC TRAVEL AGENCY";
	cout<< " " <<endl;
	cout<< "Charter Number -------------> ";
	charter_number = charter_number + 1;
	cout<< charter_number;
	cout<< " " <<endl;
	for (x= 0 ; x < 6 ; x= x+1)
	{
		cout<< "Airline Name ------------> ";
		cin>> airline_name[x];
		for(x=0 ; x<6 ; x++)
		{
**			air_duplicate[x] = airline_name[x];
		}
		cout<< "Airline Flight Number ---> ";
		cin>> flight_number[x];
		cout<< "Destination -------------> ";
		cin>> destination[x];
		for(x=0 ; x<6 ; x++)
		{
**			des_duplicate[x] = destination[x];
		}
airline_name is an array of strings. IE, it is 6 separate strings.

Therefore, airline_name[x] is one of those 6 strings.


On the other hand... air_duplicate is not an array, but instead is a single string. Therefore, air_duplicate[x] is pulling out a single character from that one string.

So this line:

air_duplicate[x] = airline_name[x];

Is attempting to assign a full string (airline_name[x]) to a single character (air_duplicate[x]). Obviously you cannot do this, since a single character is not large enough to hold an entire string.


I'm not sure what you're trying to do here, but maybe you meant to make air_duplicate an array rather than a single string?
thank you for explaining to me exactly what my incorrect code was attempting to do! it helped me figure out the solution... i was trying to create a duplicate index to sort my data alphabetically and not only did i have the create dup code in the wrong area, i hadn't declared the index. problem solved and program running correctly with no errors! thank you again for your help and "explaining to be like i'm five" as i requested! ;)
Topic archived. No new replies allowed.