小编Joh*_*nck的帖子

用C++创建一个按钮

我正在设计一个用C++编写的游戏,目前正在我的主菜单上工作,其中包括三个难度级别的三个按钮.问题是,我实际上并不知道如何在C++中创建一个按钮.我遇到了几个关于如何做到这一点的YouTube教程,但是两个人都在做视频,只是将这段代码插入到现有程序中,而我却无法弄清楚如何使用我的代码.

这是我到目前为止:

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
    system("color e0");
    cout << "Can You Catch Sonic?" << endl;
    cout << "Can you find which block Sonic is hiding under? Keep your eyes peeled for that speedy hedgehog and try to find him after the blocks stop moving" << endl;
    CreateWindow(TEXT("button"), TEXT("Easy"), WS_VISIBLE | WS_CHILD, 
        10, 10, 80, 25, NULL, NULL, NULL, NULL);
    return 0;
} 
Run Code Online (Sandbox Code Playgroud)

当我运行它时,控制台弹出正确的背景颜色和消息,但没有按钮.谁能告诉我我做错了什么?我确定它与所有这些NULL有关,但不确定要用什么替换它们.

这就是YouTube视频中的代码,但就像我说的那样,它正处于已经创建的程序中间:

CreateWindow(TEXT("button"), TEXT("Hello"), 
   WS_VISIBLE | WS_CHILD,
   10, 10, …
Run Code Online (Sandbox Code Playgroud)

c++ windows winapi button

2
推荐指数
1
解决办法
3万
查看次数

我怎样才能最好地遍历C数组?用指针还是索引?

我经常看到人们使用指针迭代C样式数组,而我发现使用索引更具可读性.下面的例子说明了我想到的两种方式.它们不会导致相同的拆卸......

我的问题:使用"跑步者"而不是索引是否有利?顺便问一下,"跑步者"技术还有另一个名字吗?

它是否依赖于底层类型,例如int,char或struct?

struct somestruct
{
    float f;
    int i;
};

const unsigned int uiSize = 10000;
somestruct * myarray = new somestruct[uiSize];
const somestruct * const pEnd = myarray + uiSize;

// way 1: runner
somestruct * pRunner = myarray;
while(pRunner < pEnd)
{
    pRunner->f += 5;
    pRunner->i += 5;
    ++pRunner;
}

// way 2: index
unsigned int ui = 0;
for (ui = 0; ui < uiSize; ++ui)
{
    myarray[ui].f += 6;
    myarray[ui].i += 4;
}
Run Code Online (Sandbox Code Playgroud)

c performance pointers

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

在JsonCPP上循环使用JSON的所有项目和文本索引

{
    "80550560": {"name":" HAdailton Cesar", "name2": "T-Max"},
    "5987810": {"name": "Adnax", "name2": "Adna Zaza"}
}
Run Code Online (Sandbox Code Playgroud)

我有这个输入,我需要输出输入中的所有名称,但问题是我没有整数有组织的索引,我将不得不得到字符串数字,我也不知道字符串是什么文本索引将是.

我会想象这样的事情,但我不知道如何从JsonCPP获取'string_text'

res[string_text]["name"];
Run Code Online (Sandbox Code Playgroud)

c++ json jsoncpp

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

恼人的strcat()输出

我在使用字符串方面遇到了一些未知问题.它只发生在这种算法的实例上:

由source.c

#include <stdio.h>
#include <string.h>
main()
{
    int cur, max;
    char ast[32];
    printf("Enter the triangle's size: ");
    scanf("%d", &max);
    for(cur = 1; cur <= max; cur++)
    {
        strcat(ast, "*");
        if(cur == 1)
        {
            printf("\n");
        }
        printf("%s\n", ast);
    }
    getch();
}
Run Code Online (Sandbox Code Playgroud)

有时候是这样的:


概述:用输入大小的星号(*)创建三角形的程序.


输入三角形的大小:5

■Z☼]vYⁿbv░↓@*

■Z☼]vYⁿbv░↓@**

■Z☼]vYⁿbv░↓@ *

■Z☼]vYⁿbv░↓@ **

■Z☼]vYⁿbv░↓@ *


它应该看起来像这样:

输入三角形尺寸:5

*

**

***

****

*****
Run Code Online (Sandbox Code Playgroud)

我不知道为什么.有人可以帮忙吗?:)

c text strcmp

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

结构的对齐不适用于#pragma pack

我有一个c ++结构:

struct a
{
     char b;
     int c;
     int d[100];
};
Run Code Online (Sandbox Code Playgroud)

结构的大小应为405字节.我看到结构的大小是408字节.原因是在整数"c"之后对齐到8个字节.数组"d"应该从结构的第6个字节开始,而不是从第9个字节开始.我用过,#pragma pack(1)但没有解决问题.我无法更改结构中字段的顺序.你知道我怎么能解决这个问题?谢谢!

c++ struct pragma

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

将日期std :: string转换为QuantLib :: Date对象

由于经常从.csv或.txt文件中读取这些字符串,我想知道获取%d/%m%/%y(或任何其他类似格式)字符串并将其转换为适合QuantLib::Date对象构造函数的最简单方法.

下面是一个示例代码:

#include <ql/quantlib.hpp>
#include <boost/timer.hpp>
#include <iostream>
#include <iomanip>
#include <boost/algorithm/string.hpp>

int main() {

  boost::timer timer;
  std::cout << std::endl;
  std::string datesString = {
    ",17/10/2014,21/11/2014,19/12/2014,20/03/2015,19/06/2015,18/09/2015,18/12/2015,17/06/2016,"
  };
  std::vector<std::string> expiryDates;
  boost::split(expiryDates, datesString, boost::is_any_of(","));
  for(int i = 0; i < expiryDates.size(); i++)
  {
    std::cout << expiryDates[i] << std::endl;
  }
  // 17/10/2014
  // 21/11/2014
  // 19/12/2014
  // 20/03/2015
  // 19/06/2015
  // 18/09/2015
  // 18/12/2015
  // 17/06/2016

  // QuantLib::Date myQLDate(?);

  return 0;

  }
Run Code Online (Sandbox Code Playgroud)

c++ date quantlib

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

检查C样式数组是否等于其他(编译时)数组

我有一个double[9]并想检查它是否包含值(1,0,0,0,1,0,0,0,1).有比这更清洁的方式吗?

if (ornt1[0] == 1 && ornt1[1] == 0 && ornt1[2] == 0
 && ornt1[3] == 0 && ornt1[4] == 1 && ornt1[5] == 0
 && ornt1[6] == 0 && ornt1[7] == 0 && ornt1[8] == 1 )
Run Code Online (Sandbox Code Playgroud)

我正在使用C++.

c++

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

stl 中的错误代码是否有任何异常?

我阅读了一些关于异常和错误代码的使用以及它们何时适合的讨论。

我相信在我的情况下例外更好,但我有一个具体问题:

如果我抛出一个 std::runtime_error("this is an error") 然后我抓住了它,我找不到错误是什么,我只知道有一个错误。

我正在寻找的是一个异常,我可以抛出并为其添加错误代码,以便稍后我可以在捕获它时检查错误代码,例如:

 enum errorCodes
 {
        error_1,
        error_2,
        error_3
 }

 try
 {
     throw std::runtime_error(error_1,"can not do the job!");
 }
 catch (std::runtime_error & err)
 {
     switch (err.errorCode)
     {
         case error_1:
            // I can not contunue, so re throw it
             rethrow err;
         case error_2:
            // it is not important for me, so I can continue
           break;
        case error_3: 
            //Oh, I need to do something before continue
            re_init();
            break;
        default:
             rethrow err;
  }
Run Code Online (Sandbox Code Playgroud)

我可以写这样的异常,但在这样做之前,我想知道 STL 或 BOOST …

c++ boost stl exception

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

多维矩阵的最后一个元素

我有一个多维矩阵,并希望将最后一个元素设置为1.(例如w[1,1,1,1,1]= 1),维度变化,这就是我的问题.po[-1]=1在这里不起作用.

python numpy multidimensional-array

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

'%% file test.py'在python中意味着什么?

正如标题所说.我想弄清楚'%%'是什么意思.它似乎不是占位符吗?

%%file test_theano.py
from theano import config
print 'using device:', config.device
Run Code Online (Sandbox Code Playgroud)

python ipython ipython-magic

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