I can convert char to string but not string to char
I am creating a program in C++ to break down a character array that the user enters into individual characters and then to add them to a 2d array. The bits of the keyword are stored in char's j-l. when I try to give the value of the chars to a part of the array it doe not work but when I try to give开发者_开发百科 the value of a part of the array to the chars it works. Someone will probably mention the conflict between string functions and arrays and char variables. Exept for this one little problem the setup works for me and if I try to change it it comes up wih some errors. Is there a simple way to fix this problem without changing the arrays and function to a different type? If not please tell me what to do, I am only a beginner.
while (key[a] != '\0' ){
while(b <= 4){
m++;
cipherarray[b][c] = key[a];
if (m == 1 ) {
if I swith this to "cipherarray[b][c] = f;" it works but then cipherarray[b][c] = "q"
f = cipherarray[b][c];
}
if ( m == 2 )
{
g = cipherarray[b][c];
}
if ( m == 3 )
{
h = cipherarray[b][c];
}
if ( m == 4 )
{
i = cipherarray[b][c];
}
if ( m == 5 )
{
j = cipherarray[b][c];
}
if ( m == 6 )
{
k = cipherarray[b][c];
}
if ( m == 7 )
{
l = cipherarray[b][c];
}
a++;
b++;
if (key[a] == 0)
break;
}
if (key[a] != 0){
c++;
b = 0;
}
}
By the way this is the error i get:
incompatible types in assignment of std::string
to char[2]
I just changed al of the chars to strings and the function decalation. I have been slaving over this for so long I could not see how obvious it was to fix.
精彩评论