小编Lio*_*ing的帖子

无法将类型'bool'隐式转换为'System.Windows.Forms.RightToLeft'

我有这个错误.我知道转换和其他转换,但我怎样才能转换为System.Windows.Forms.RightToLeft

码:

this.RightToLeft = false; // Here is the problem
this.Text = "Do you speak english ?";
Run Code Online (Sandbox Code Playgroud)

.net c# winforms right-to-left

0
推荐指数
1
解决办法
1482
查看次数

事件未在方法内定义

以下对象有什么问题.

var events = {
    targetElem: function(e) {
        var eve = (e) ? e : window.event;
        if (eve.target)
            alert(eve.target);
        else
            alert(eve.srcElement);
    }
};
Run Code Online (Sandbox Code Playgroud)

总是给我看错误信息ReferenceError: e is undefined.

javascript javascript-events

0
推荐指数
1
解决办法
147
查看次数

如何计算2D数组的项目?

我想计算2D数组中的项目数.

例如

char arr[][10] = {"Hello", "I'm", "Jack"};
Run Code Online (Sandbox Code Playgroud)

先前的阵列具有3行(Hello,I'm,Jack)和类似的10柱(Hello5从10长度).

每个人都知道,当我们想要获得具有单个维度的数组时,我们会执行以下操作.

int size = (sizeof(arr) / sizeof(char));
Run Code Online (Sandbox Code Playgroud)

但是现在我们需要一种方法来了解数组中有多少行?
另一种方法是知道,阵列中还有多少列,单独?

c++ multidimensional-array

0
推荐指数
2
解决办法
2444
查看次数

__cplusplus 在 MSVC 中等于 199711,是否支持 C++11?

我想知道我的编译器是否支持 C++11,当使用 const__cplusplus知道 C++ 版本时,我发现打印199711.

这个版本号是不是表示编译器支持C++11?
注意:我正在使用Visual Studio 2013 v12.0.40629 Update5.

c++ visual-c++ c++11

0
推荐指数
1
解决办法
4069
查看次数

带有"new"的指针和带有"&variable"的指针之间有什么区别

我有一个简单的问题,但有时候我有点困惑.

第一个代码:

Person *ptoPerson = new Person;
cout << ptoPerson->printMsg("Hi") << endl;
delete ptoPerson;
Run Code Online (Sandbox Code Playgroud)

第二个代码:

Person p;
Person *ptoPerson = &p;
cout << ptoPerson->printMsg("Hi") << endl;
delete ptoPerson;
Run Code Online (Sandbox Code Playgroud)

删除指针时会发生此问题.
第一个代码工作正常,指针删除,但第二个代码在实现它时出现问题在运行时.

为什么第二个代码无法删除指针?
我认为这两种情况下的指针是一个指针,可以删除它,或者我错了.

c++ pointers

0
推荐指数
1
解决办法
123
查看次数

从类成员返回智能指针的正确方法?

我正在尝试在person类中编写单例模式,这使我能够为该类创建一个实例,并且我可以在我的程序中的任何位置使用它.

以下是班级:

// The declaration
class Person {
    static unique_ptr<Person> instance;
    Person() = default;
    Person(Person&) = delete;
    Person& operator=(const Person&) = delete;
    ~Person() = default;
public:
    static unique_ptr<Person> getInstance();
};

// The implementation   
unique_ptr<Person> instance = NULL;
unique_ptr<Person> Person::getInstance() {
    if (instance == NULL) {
        instance = unique_ptr<Person>(new Person());
    }
    return instance;
}
Run Code Online (Sandbox Code Playgroud)

但它给我这个错误的问题: Error C2280 'std::unique_ptr<Person,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)': attempting to reference a deleted function

不幸的是,我不明白这个问题,我不知道如何解决?

c++ singleton smart-pointers c++11

0
推荐指数
1
解决办法
249
查看次数

如何以编程方式设置应用程序EXE文件的图标?

如何以编程方式将默认应用程序图标更改为自定义图标,即不使用资源文件(只需在EXE文件旁边放置一个图标).

我只知道一种使用资源文件的方法,但我想知道一种以编程方式执行此操作的方法(代码和外部图标).

另外,我尝试了以下代码:

HANDLE hIcon = LoadImage(0, L"icon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
HWND hwnd = GetConsoleWindow();
if (hIcon) {
    //Change both icons to the same icon handle.
    SendMessage(hwnd, WM_SETICON, ICON_SMALL,(LPARAM) hIcon);
    SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM) hIcon);

    //This will ensure that the application icon gets changed too.
    SendMessage(GetWindow(hwnd, GW_OWNER), WM_SETICON, ICON_SMALL, (LPARAM) hIcon);
    SendMessage(GetWindow(hwnd, GW_OWNER), WM_SETICON, ICON_BIG, (LPARAM)hIcon);
}
Run Code Online (Sandbox Code Playgroud)

但该代码只是更改窗口左下角的图标,而不是应用程序EXE文件.

如何以编程方式设置应用程序EXE文件的图标?

c++ winapi

-1
推荐指数
1
解决办法
90
查看次数

如何创建一个循环来获取std :: map的内容

我需要使用关联数组,当听说STL std::map我决定使用它时,我有以下代码.

map<string, string> aArray;
aArray["First"] = "William";
aArray["Second"] = "James";
aArray["Third"] = "Michael";
aArray["Forth"] = "Jayden";
aArray["Fifth"] = "Ashley";

for(std::map<string, string>::iterator it=aArray.begin();it!=aArray.end();++it){
    cout << it << endl;
}
Run Code Online (Sandbox Code Playgroud)

但我不知道如何制作有效的循环.
我在其他教程中看到过如下:

cout << it->first << endl;
cout << it->second << endl;
Run Code Online (Sandbox Code Playgroud)

但也有指定的任何成员first,second.

还有一个错误:

  • no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'std::map<std::basic_string<char>, std::basic_string<char> >::iterator {aka std::_Rb_tree_iterator<std::pair<const std::basic_string<char>, std::basic_string<char> > >}')

请向我解释我该怎么做?

c++ iterator stl stdmap

-2
推荐指数
1
解决办法
375
查看次数

当我们初始化数据类型char*时,什么时候不?

首先,看看下面的简单代码:

char str[80] = "This is - my text - for test";
const char s[2] = "-";
char *token;
token = strtok(str, s);

while (token != NULL) {
    printf(" %s\n", token);   
    token = strtok(NULL, s);
}
Run Code Online (Sandbox Code Playgroud)

该函数strtok()返回数据类型char*,如您所见,我们创建了一个名为token该变量未初始化的变量.

现在,看看下一个代码:

char *buff;
int num = 500;
sprintf(buff, "%d", num);
Run Code Online (Sandbox Code Playgroud)

上一个代码的结果是错误uninitialized local variable 'buff'.
我的问题是,为什么在第一个代码中没有出现任何问题,而在第二个代码中发生了错误?

c++ variable-initialization

-2
推荐指数
1
解决办法
56
查看次数