How to store CString using Vector in C++

haroonrulz's Avatar
Email Reported As Spam
Dear Gurus/Experts in C++,

I am new to C++.My Question is very basic.I need CString to be stored in Vector, as I am new even after several attempts I dont know how to do it.Kindly help me.My code is as below:


void Editcontrol(CString prop1,CString prop2,CString prop3)
{
Vector <string> v;

// I need to store CString in Vector, even after many tries I could not able to do it
}


int main()
{
Editcontrol("Haroon","Rizwan","Noor");

}
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
If you want a vector of CStrings then the definition would be vector<CString>. vector<string> will give you a vector of strings, not CStrings.

C++ is case sensitive so vector and Vector are not the same thing.

This is only a guess, because you didn't say why you couldn't do it. I'm guessing you got some sort of error, would that be correct?
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Here's some code I just wrote:
Code:
void test51()
{
	vector<string> v;
	v.push_back("Hello");
	v.push_back("World");
}
0
Becks's Avatar, Join Date: Feb 2013
Newbie Member
Here is an example how to store a textfile (each line) in a vector.
Code:
#include <vector>
#include <fstream>

using namespace std;

        ifstream myfile(path.c_str());
	char zeile [500];
	if (myfile)
	{
		int b=0;
		while(myfile.getline(zeile, 500))
		{
			line.push_back(zeile);


		}

		myfile.close();
}
path is just a string which stores the path to the txt-file
shabbir like this