string array to character array

how do i convert a string array to character array ?

whats the meaning of this error "cannot convert `std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to `char' in assignment "

char line[100];
string arr[100];

for(i=0;i<count;i++)
{
line[100]=arr[i];//basically arr contains words which i want to place in a char array//
cout<<line<<endl;
}

is dis right?

maybe you want to look into this ;)

http://www.cplusplus.com/reference/string/string/c_str/

regards
No, it is not right. You should make a new string, and add up all the stuff in arr to it, and then make line the c-string equivalent of that new string. Something like this:
1
2
3
4
5
6
7
8
9
char line[1000];
string arr[100], newstring="";
for(i=0;i<count;i++)//assuming count is th number of items in arr
{
newstring+=arr[i];
}
line=newstring.c_str();
cout<<line<<endl;
}
closed account (zvRX92yv)
Plus, you can't access the 101th slot of a 100-slot array..
I suggest you re-read/read the tutorial on this site.
Hi try this one ..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
using namespace std ; 


int _tmain(int argc, _TCHAR* argv[])
{
	const int count = 5;
	char name[100]; 
	string name_array[count] = { "Bill" , "Jill" , "Mill" , "Till" , "Vill" } ; 
	for( int i = 0 ; i < count ; i++ )
	{
		strcpy( name , name_array[i].c_str() );
		cout<< " \n The Name = " <<name;
	}

	return 0;
}
oh great!!thanks people
Topic archived. No new replies allowed.