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"); }
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?
Here's some code I just wrote: Code: void test51() { vector<string> v; v.push_back("Hello"); v.push_back("World"); }
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