Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   How to store CString using Vector in C++ (http://www.go4expert.com/forums/store-cstring-using-vector-cpp-t29061/)

haroonrulz 7Sep2012 12:14

How to store CString using Vector in C++
 
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");

}

xpi0t0s 8Sep2012 11:55

Re: How to store CString using Vector in C++
 
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?

xpi0t0s 8Sep2012 11:58

Re: How to store CString using Vector in C++
 
Here's some code I just wrote:
Code:

void test51()
{
        vector<string> v;
        v.push_back("Hello");
        v.push_back("World");
}


Becks 7Apr2013 16:45

Re: How to store CString using Vector in C++
 
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


All times are GMT +5.5. The time now is 06:08.