std :: vector <std :: string>和push_back

时间:2017-10-21 22:41:53

标签: c++

我操作了很多网站,所以我试图使用

创建我的列表
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <windows.h>
//.......................................
#include "stdafx.h"

 HWND vbrowser;
 std::vector<std::string> sites;
 sites.push_back("https://hardcoregames.azurewebsites.net/wp-admin/");


 wchar_t *convertCharArrayToLPCWSTR(const char* charArray)
 {
//  wchar_t* wString = new wchar_t[4096];
    MultiByteToWideChar(CP_ACP, 0, charArray, -1, wString, 4096);
    return wString;
 }

 int main()
{
     CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    ShellExecute(vbrowser, convertCharArrayToLPCWSTR("open"), convertCharArrayToLPCWSTR(url.c_str()), NULL, NULL, NULL);
     return 0;
 }

所以我在想,我可以对网站进行硬编码,我只运行一些

但是在我尝试使用时:

 sites.push_back ("https://hardcoregames.azurewebsites.net/wp-admin/");

2017年vc不喜欢,说没有存储类或类型说明符,那么它建议我使用分号;

我的项目是打开管理页面,等待一点,然后再转到下一个站点

vc 2017社区版

我希望能够在wordpress中显示管理员屏幕

CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
ShellExecute(vbrowser, convertCharArrayToLPCWSTR("open"), convertCharArrayToLPCWSTR(url.c_str()), NULL, NULL, NULL);

1 个答案:

答案 0 :(得分:1)

你在一个函数之外调用一个成员函数 - 除了在初始化变量时,这在C ++中是非法的。 具体来说,这一行:

class node{
private:
    int data;
    node* next;
    int mark;
public:
    node(int d = 0, node* n = NULL){
        data = d;
        next = n;
        mark = 0;
    }
    int getdata(){return data;}
    node* getnext(){return next;}
    int getmark(){return mark;}
    void setdata(int x){data = x;}
    void setnext(node* x){next = x;}
    void setmark(int x){mark = x;}
};
class list{
private:
    node* L1; //head pointers to list1, list2, and freelist.
    node* L2;
    node* free;
    node* front;
public:
    list(){
        front = new node();  //generate free list (empty)
        free = front;
        L1 = NULL;
        L2 = NULL;
        node* p = free;
        for (int i = 1; i < 10; i++){
            p -> setnext(new node());
            p = p -> getnext();
        }
        delete p;
    }

    void insert(int a, int x){
        if (free == NULL) {
            cout << a << " is full. can't insert " << x << " into the list." << endl;
            return;
        }
        if (a == 1) node* &list = L1;
        else if (a == 2) node* &list = L2;
        else {
            cout << "not a valid list";
            return;
        }
        if (list == NULL){
            list = free;
            free = free -> getnext();
            list -> setdata(x);
            list -> setnext(NULL);
        }
        else {
            node* p = list;
            while (p -> getnext() != NULL) {p = p -> getnext();}
            p -> setnext(free);
            free = free -> getnext();
            p -> getnext() -> setnext(NULL);
            p -> getnext() -> setdata(x);
        }
    }
};

必须在某个地方的某个功能内。

您可以使用以下命令在编译时设置sites.push_back("https://hardcoregames.azurewebsites.net/wp-admin/"); 的值:

vector

正如您在评论中指出的那样,这是一个变量初始化。

或者,你可以将你的std::vector<std::string> sites = { site1, site2 }; 语句移动到push_back函数中,只需在程序启动时运行它 - 你甚至可以全力以赴地摆脱全局变量而转向本地变量(这将是一个非常好的设计选择...)