problem

Write your question here.
Hi everyone
I write like this

vector<char> names;
vector<int> radii;


names.push_back("Mercury");
radii.push_back(2440);
and have error
C++ class "std::vector<char, std::allocator<char>>" has no member "push_back"
and
C++ class "std::vector<char, std::allocator<char>>" has no member "push_back"

plz hoe can i fix it
Use string
I did and same issue
Please post a small whole program that we can try to compile, and the exact error message that you get with it.


PS. You already had thread http://www.cplusplus.com/forum/beginner/238128/ on this topic. Do not doublepost.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
   vector<char> names;
   names.push_back("Mercury");         // <==== THIS WILL FAIL
   // Now COMMENT THE ABOVE LINE OUT leaving just the following ...
   vector<string> moreNames;
   moreNames.push_back("Mercury");

   // Notice the difference?
   //    vector<char> or vector<string>
}
Last edited on
Topic archived. No new replies allowed.