且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

传递字符串数组矢量C ++

更新时间:2023-02-12 15:32:29

  URLvector.assign(URLpolicy,URLpolicy + noURL);

可用于字符串数组传递到一个载体

I am tring to push an array of strings to a vector, like this:

 string []URL = {"www.facebook.com","www.orkut.com","www.yahoo.com"};
 Int32 result = URL.Length;
 SetPolicyURL( URL,result);

 SetPolicyURL( char * URLpolicy[], __int32 noURL)
 {
__int32 i  = 0;

while ( i< noURL)
{
    char buf[2512] = {0};

    URLvector.push_back(URLpolicy[i]);
    sprintf( buf," noURL = %d URLpolicy[%d] = %s  URLvector[%d] = %s", noURL,  i,URLpolicy[i] ,i, URLvector.at(i).c_str());


    MessageBoxA(NULL, buf , 0, MB_ICONERROR);

    ++i;
}

}

But when I try to display the elements of the vector, I am only getting the first array element twice, and the 2nd element of the array in position 3. I am not getting whyy this is happening.

URLvector.assign(URLpolicy,URLpolicy+noURL) ;

can be used to pass the array of strings to a vector.