标签: visual-c++

C++无法填充C数组的映射

typedef std::map<std::string,int> string2intMap;
typedef string2intMap arrOfMaps[3] ;

//map : string --> array of maps of <std::string,int>
std::map<std::string,arrOfMaps> tryingStuff;

//map : string --> int
string2intMap s;
s["key"]= 100;

tryingStuff["hello"][0] = s;
Run Code Online (Sandbox Code Playgroud)

上面的代码没有编译,有问题的行是:tryingStuff ["hello"] [0] = s;

这是编译器大喊:

c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(215): error C2440: '<function-style-cast>' : cannot convert from 'int' to 'std::map<_Kty,_Ty> [3]'
2>          with
2>          [
2>              _Kty=std::string,
2>              _Ty=int
2>          ]
2>          There are no conversions to array types, although there are conversions to references or pointers to …
Run Code Online (Sandbox Code Playgroud)

c++ arrays typedef visual-c++

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

在0xccccc访问读取违规

我不知道为什么会这样; 一些谷歌搜索让我相信它是由于不正确的内存管理,而其他人则说这是因为链接到可执行文件的无效.DLL.我似乎无法解决这个问题,因为我能想到的唯一.DLL是无效的.我的freeglut .DLL,但它本身没有任何问题.

我要做的就是创建一个窗口.

我的代码发生了什么?我做错了什么,我该如何解决?

WinMain

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
LPSTR lpszCmdLine, int nCmdShow) {

    WNDCLASSEX wc;
    HWND hwnd;
    MSG     msg;
    bool    done;

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    wc.lpszClassName = L"someclass";

    if (!RegisterClassEx(&wc)) { //Error: 
        MessageBox(NULL, L"Class registration has failed!", L"Error!", MB_OK | MB_ICONINFORMATION);
        return 0;
    }

    hwnd = …
Run Code Online (Sandbox Code Playgroud)

c++ winapi runtime-error visual-c++

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

gcc深/双/嵌套铸造

首先是代码

#include <stdio.h>

typedef wchar_t* BSTR;

wchar_t hello[] = L"Hello";

class _bstr_t {
public:
    operator const wchar_t*() const throw() { return hello; }
    operator wchar_t*() const throw() { return hello; }
};

class container {
public:
    operator _bstr_t() { return _bstr_t(); }
};

int main()
{
    // This gives error (with gcc 4.5.2 at least):
    // test.cpp:20:27: error: cannot convert "container" to "wchar_t*" in initialization
    wchar_t *str = container();
    printf("%S\n", str);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这里的问题是container()可以转换为_bstr_t然后wchar_t* …

c++ gcc visual-c++

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

在模板中使用std :: max时出错

我可以在模板函数中使用std函数吗?我有补充和写作

#pragma region BlendFunctions

template <class T> 
T BlendLightenf(T x, T y) 
{ 
    return std::max(x, y); //errors here
} 
template <class T> 
T BlendDarkenf(T x, T y) 
{ 
  return std::min(x, y); //errors here
} 
Run Code Online (Sandbox Code Playgroud)

得到

error C2589: '(' : illegal token on right side of '::'
Run Code Online (Sandbox Code Playgroud)

error C2059: syntax error : '::'
Run Code Online (Sandbox Code Playgroud)

在一个字符串中(通常是x和y float).

我定义:

#ifdef MAGICLIB_EXPORTS
#define CPPWIN32DLL_API __declspec(dllexport)
#else
#define CPPWIN32DLL_API __declspec(dllimport)
#endif


#include <stdio.h>
#include <string>
#include <algorithm> 
Run Code Online (Sandbox Code Playgroud)

c++ templates compiler-errors max visual-c++

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

bool __cdecl func(void)已在func.obj中定义

我越来越

error LNK2005: "bool __cdecl hasLogin(void)" (?hasLogin@@YA_NXZ) already defined in B.obj
Run Code Online (Sandbox Code Playgroud)

错误.funcB.cpp文件中声明,并从A.cpp文件中调用.B.cpp包括在内A.cpp.谷歌说,包括cpp在另一个方面是不好的cpp.如果我复制/粘贴funcA.cpp没有任何问题.如何正确解决tsis问题?

PS我是c ++的新手,如果问题是转储,请原谅.

c++ visual-studio-2010 visual-c++

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

RegQueryValueEx的问题

请参考以下代码

HKEY hKey = 0;
int code = RegOpenKey(HKEY_CURRENT_USER, subkey, &hKey); //code is ERROR_SUCCESS

char aBuf[255] = {0};
char bBuf[255] = {0};
DWORD dwType = REG_SZ;
DWORD dwBufSize = sizeof(bBuf);

int aCode = RegQueryValueEx(hKey, L"a", 0, &dwType, (BYTE*)aBuf, &dwBufSize);
int bCode = RegQueryValueEx(hKey, L"b", 0, &dwType, (BYTE*)bBuf, &dwBufSize);
//(*) here I have a breakpoint
Run Code Online (Sandbox Code Playgroud)

在断点aBuf(以及bBuf)是类似的'a' '\0' 'v' '\0' 'a' '\0' 'l' '\0' 'u' '\0' 'e' '\0'.我究竟做错了什么?

先感谢您!

c++ visual-c++

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

无法从const char []转换为std:string*

在visual c ++ cli项目文件中,我创建了以下类(c ++类型).无法解析适合名称变量的字符串或char类型.

#include <vector>
#include <string.h>
using namespace std ;

class MyClass 
{
public :
int x;
int y;
string * name;

void foo() { name = "S.O.S" ;}
};
Run Code Online (Sandbox Code Playgroud)

Ps.型铸造错误

c++ c++-cli visual-c++

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

Visual C++ - 运行时检查失败#3 - 变量未初始化

我使用Visual C++ 2010 Express Edition来编译和运行我用C++编程语言编写的.exe文件.我正在尝试使用C++创建一个基于循环的逻辑来询问用户他选择输入多少条目,并提出仅限于该条目的问题.的条目.例如,我想输出"你想输入多少个字符?:"说用户给出答案为'3',它存储在int变量'entries'中.然后我想在问题停止之前继续问3次并继续下一行代码.我希望你理解,这是一段代码来展示我在做什么:

#include <iostream>
#include <string>
using namespace std;

int main()
{
   cout << "How many values do you need to enter?: ";
   int entries;
   cin >> entries;
   int offset, number;
   string valueName[50];
   float valueValue[50];
   for (offset = 0; offset < entries; offset++)
   {
      cout << "Enter " << number << " Value Name: ";
      cin >> valueName[offset];
      cout << "Enter " << valueName[offset] << "\'s value: ";
      cin >> valueValue[offset];
      for (number = 1; number <= …
Run Code Online (Sandbox Code Playgroud)

c++ loops for-loop runtime visual-c++

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

WM_GETTEXT用法

我正试图在我的应用程序中获取文本字段的状态.但是我没有让它发挥作用.我正在使用"SendMessage"获取"WM_GETTEXT",我将内容保存为char*.

我将char*输出到一个文件,但我只返回"D".这就是我现在拥有的:

LRESULT result;
char * output = (char*)malloc(1024);

result = SendMessage(hwnd,WM_GETTEXT,1024,(LPARAM)output);

ofstream file("test.txt");
file <<  *output;
file.close();

delete [] output;
Run Code Online (Sandbox Code Playgroud)

windows visual-studio-2005 sendmessage visual-c++

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

这个MSVC符号是什么意思?

我注意到项目源文件上的这个小标志,并不知道它的含义.

在此输入图像描述

c++ visual-c++

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