I am new to pointers and I was wondering if someone can take a look at my code and tell me why I am getting an error ” invalid conversion from Char to Char;
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main (int argc, char * const argv[]) {
int stringlenght;
string input;
cout << "Please enter a string >";
getline(cin,input);
cout << "You entered: " << input << endl << endl;
stringlenght=input.length();
cout << stringlenght;
char *inputArray[stringlenght];
for (int i=0; i < stringlenght; i ++) {
inputArray[i]=input[i];
}
//system("pause");
}
The problem with your example is that you have declared inputArray as an array of pointers to characters, and therefore inputArray[i] will be a pointer to a character.
What you are trying to do is assign the pointer at the i:th position in inputArray a character value.
What I think you would like to do is to declare inputArray as:
This instead creates one pointer, and makes it point to a contigous area in memory where you can store characters, and therefore the type of inputArray[i] will be char instead of char *.