STL Vectors in visual studio

Is there a way to include strings directly STL vectors in visual studio C++> I can get integers and single letters to work, but not strings.
I don't 100% understand your question but, if you want to use strings you have to #include <string>

If you want to use vectors you'll have to #include <vector>
Despite my question I DO know enough to include the headers. Integers and single characters I can put in a vector without problems. But when I try to insert a std::string the compiler (Visual c++ 2013) balks. I could use string collection, but felt originally that Vector would be the right way to go.
So what's the error message you're getting?
Please post a minimal example that is demonstrating the problem along with (as Peter87 asked) the error messages.
Here is the code that works

// ConsoleVector.cpp : Defines the entry point for the console application.
// From Help sample

#include "stdafx.h"
#include <cliext/vector>


int main()
{
cliext::vector<int> VTitle;
VTitle.push_back(144);
VTitle.push_back(73);
VTitle.push_back(37);
for each(int elem in VTitle)
System::Console::Write("\n {0} ", elem);
System::Console::WriteLine();

// outputs line 144 73 37
return 0;
}


#include "stdafx.h"
#include <cliext/vector>
#include <string>


int main()
{
cliext::vector<std::string> VTitle;
VTitle.push_back("alcatraz");
for each(std::string elem in VTitle)
System::Console::Write("\n {0} ", elem);


return 0;
}

THe error message is "Error 42 error C2259: 'cliext::vector<std::string>' : cannot instantiate abstract class C:\CPP2013\ConsoleVector\ConsoleVector\ConsoleVector.cpp 11
"
closed account (E0p9LyTq)
System::Console::Write() isn't standard C++, neither is your vector header include.

1
2
3
4
5
6
7
8
9
#include <vector>
#include <string>

int main()
{
   std::vector<std::string> VTitle;

   VTitle.push_back("alcatraz");
}
Last edited on
@Aquilifer
The problem is you are trying to use a .Net container to store a non .Net type. Either use cliext::vector<System::String^> or use std::vector<std::string> and convert to System::String to use Console::Write.
Naraku,
If I understand you correctly, you are saying that vector is a .NET type, but that string isn't .NET. What can I use instead of string that would work??
You can use System::String like this:
 
System::String^ str = gcnew System::String("MyString");
Topic archived. No new replies allowed.