Previously I've asked a question and got a small answer but now I'm taken to a point in which I'm unable to compile this code successfully. I'm attempting to build a shop type database, for now I can do with simply using an array of strings. But I've been recommended that using an array of strings is bad practise to use in C++ and isn't a good idea to continue with. So for future reference I'd like to this done so I may be later tackle on vectors in my exam.
#include "string"
#include "vector"
#include "iostream"
using namespace std;
class shop
{
private:
int i, n, item[20];
float price[20];
std::vector<std::string> name;
public:
void input();
void output();
};
void shop::input()
{
cout << "Enter the number of items: ";
cin >> n;
name.clear();
name.push_back(n);
name.resize(n);
for(i = 1; i <= n; i++)
{
cout << "Enter the item number of the " << i << " item: ";
cin >> item[i];
cout << "Enter the name of the item: ";
cin >> name[i];
cout << "Enter the price of the item: ";
cin >> price[i];
}
}
void shop::output()
{
for(i = 1; i <= n; i++)
{
cout << "Item Number: " << item[i] << endl;
cout << "Price: " << price[i] << endl << endl;
cout << "Name: " << name[i] << endl << endl;
}
}
void main()
{
class shop s;
s.input();
s.output();
}
But the error I get is:
1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1> Source.cpp
1>c:\users\khale_000\documents\visual studio 2013\projects\project1\project1\source.cpp(20): error C2664: 'void std::vector<std::string,std::allocator<_Ty>>::push_back(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)' : cannot convert argument 1 from 'int' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&'
1> with
1> [
1> _Ty=std::string
1> ]
1> Reason: cannot convert from 'int' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========