Im trying to make a basic inventory management c++ program, what im trying to do is to add specific value (string) into array inventory (string too)
here's the code:
#include <string>
class OurInventory{
private:
int size;
std::string inventory;
public:
void createArr(){
std::cin >> size;
std::string* inventory = new std::string[size];
std::cout << "Created array with size of " << size << std::endl;
}
void addItem(){
int userInputIndex;
std::cin >> userInputIndex;
if(userInputIndex >= size){
std::cout << "Wrong value!";
}
else{
std::string userInputData;
std::cin >> userInputData;
inventory[userInputIndex] = userInputData;
}
}
};
int main(){
OurInventory obj;
obj.createArr();
obj.addItem();
}```
Its excepted to give me a prompt which asks the specific index and what i want to add to that index.
What it gives me is this:
``` error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to '__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type' {aka 'char'} in assignment
25 | inv[userInputIndex] = userInputData;
| ^~~~~~~~~~~~~
| |
| std::string {aka std::__cxx11::basic_string<char>}```