0

My code:

#include <vector>
std::vector<std::string> keyNamesList = { "A", "B" };

Won't compile, getting the error:

No matching constructor for initialization of std::vector<std::string>

Which is weird, because I am using C++11 (Xcode LLVM) and the line above it which does compile is a std::vector<int> = { 1, 2 };

This has to work. Any thoughts?

  • Can you post an [mcve]? – sfjac Dec 18 '15 at 00:49
  • 2
    I'm voting to close this question as off-topic because it is not generally useful. – IInspectable Dec 18 '15 at 00:52
  • @IInspectable I was just waiting for the OP to confirm that Kerrek's solution was correct. – SirGuy Dec 18 '15 at 00:53
  • @iinspectable that is a horrible idea. I posted a coding question with a simple answer in which Kerrek answered correctly. Please consider reading questions to completion in the future. I will be marking Kerrek's answer correct as soon as SO allows me. – Jason Braham Dec 18 '15 at 00:55
  • @JasonBraham: C++ developers know to include header files. This question has no value to them. Closing a question that isn't useful is the right decision. – IInspectable Dec 18 '15 at 00:56
  • @iinspectable C++ developers come in many shapes and sizes, new and experienced. You're going to have to eat your pride on this one and admit you are wrong (not looking for a public apology, just want you to think more critically in the future for the better of the community). – Jason Braham Dec 18 '15 at 00:59
  • @JasonBraham: You are dreaming up SO to be the community you want it to be. It doesn't work like that. Please take the [tour](http://stackoverflow.com/tour) to learn, what SO is. – IInspectable Dec 18 '15 at 01:01
  • @iinspectable after reading the tour I am even more certain of my position. "answers to every question about programming" and "Focus on questions about an actual problem you have faced." If you are uncertain what SO is about please pass along when you do not know the answer. – Jason Braham Dec 18 '15 at 01:04
  • @JasonBraham: How is your question useful to others? It has a misleading title (please read [Asking](http://stackoverflow.com/help/asking), all of it), doesn't show any research effort, and is really asking for the absolute basics, explained in **any** introductory book from [The Definitive C++ Book Guide and List](http://stackoverflow.com/q/388242/1889329). If you cannot resist responding, you'll have the last word. – IInspectable Dec 18 '15 at 01:13
  • @iinspectable I did some research, no answer. I had a problem that was answered. I am certain others will run into this problem in the future. Sorry I have had to chastise you but you are objectively wrong here and you are clearly grasping at strings to save your pride. All I ask is you use more critical thinking in the future to better the community. – Jason Braham Dec 18 '15 at 01:15
  • @iinspectable Question is now closed, but with a valid answer... Everybody should be happy now. – Macmade Dec 18 '15 at 02:34

1 Answers1

4

You also need to #include <string>.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084