小编Kir*_*lev的帖子

C++ - 使用typeof运算符给出错误的宏

我正在从这个topcoder链接学习C++(STL):https://www.topcoder.com/community/data-science/data-science-tutorials/power-up-c-with-the-standard-template-library- part-1 / 并且作者使用了宏,这是我第一次学习.我试图以下面的方式使用它,但我得到一些错误:

#include <iostream>
#include <vector>
#include <set>

//Macros

#define tr(container, it)\
    for(typeof(container.begin()) it = container.begin(); it!=container.end(); it++);

using namespace std;

int main()
{
    set< pair<string, pair< int, vector<int> > > >SS; 
    int total = 0; 
    tr(SS, it) { 
        total += it->second.first; 
    }
    return 0; 
}
Run Code Online (Sandbox Code Playgroud)

错误:在使用宏的行上,我收到一个错误 - >'it'未在此范围内声明.请帮忙!谢谢!

c++ macros

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

GetProcAddress函数返回NULL

我试图动态加载C++ DLL,首先我使用"LoadLibrary"函数加载dll并正确处理它的句柄.之后我尝试使用"GetProcAddress"获取DLL文件函数的函数指针,它返回NULL.请找到我的DLL代码并测试应用程序代码,并告诉我代码中出错的地方.

dummy2.h

namespace newer
{
  class dllclass
  {
    public:
        static __declspec(dllexport) int run(int a,int b);
  };
}
Run Code Online (Sandbox Code Playgroud)

dummy2.cpp

#include <iostream>
using namespace std;

#include "dummy2.h"

namespace newer
{
  int dllclass::run(int a,int b)
  {
    return a+b;
  }
}
Run Code Online (Sandbox Code Playgroud)

dummy1.cpp

#include "stdafx.h" 
#include <windows.h>

#include <iostream>
using namespace std;
typedef int (*Addition)(int,int);

int _tmain(int argc, _TCHAR* argv[])
{
  Addition add;
  HINSTANCE hDLL;
  hDLL = LoadLibrary(TEXT("Dummy2.dll"));

  add = (Addition)GetProcAddress(hDLL, "run");  

  getchar();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

请参考上面的代码并指导我.

c++ windows dll getprocaddress

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

重置源文件更改检测

有时我必须处理能够使计算机时钟向前移动的代码.在这种情况下,一些.cpp或.h文件将其最新修改日期设置为将来的时间.

稍后,当我的时钟被修复,并且我编译我的源时,系统会重建大部分项目,因为将来会有一些最新的修改日期.每次后续重新编译都有同样的问题.

我知道的解决方案是:

a)找到具有未来时间的文件并重新保存.这种方法并不理想,因为项目非常大,甚至Windows高级搜索也需要时间来查找更改的文件.

b)删除整个项目并从svn重新检查.

有谁知道如何解决这个问题?

在visual studio中是否有一个设置允许我告诉编译器使用存档位而不是最后修改日期来检测源文件更改?

或者可能有一个递归修改日期重置工具,可以在这种情况下使用?

c++ svn time timezone visual-studio

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

循环中的宏?

for(x;x<crap;x++)
{
    macro(x,y);
}
Run Code Online (Sandbox Code Playgroud)

预处理器如何处理?这个循环是展开还是别的?

macros preprocessor loops

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

如何在c#中将"2003-11-05T16:35:30Z"转换为"11/5/2013"​​?

我在转换时遇到问题

 2003-11-05T16:35:30Z  to "11/5/2013"
Run Code Online (Sandbox Code Playgroud)

我在下面试过

 DateTime.ParseExact("2003-11-05T16:35:30Z", "dd/MM/yyyy", null)
Run Code Online (Sandbox Code Playgroud)

但我没有得到我期望的价值.

c# datetime type-conversion

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

SysFreeString没有释放变量

任何人都可以帮助我理解为什么下面的代码在分配后没有释放内存.

BSTR ys;
{
    ys = ::SysAllocString(L"Asdfghjk");
    {
        ::SysFreeString(ys);
    }
}
wcout << ys; // *I could see "Asdfghjk" in console window*
Run Code Online (Sandbox Code Playgroud)

c++ com winapi visual-c++

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

reinterpret_cast&lt;char *&gt;(&amp;st) 和 (-1)*static_cast&lt;int&gt; 是什么意思?

此处的代码用于创建学生成绩单项目。在尝试理解时,我们无法弄清楚以下代码的用途和功能:

File.read(reinterpret_cast<char *> (&st), sizeof(student));

int pos=(-1)*static_cast<int>(sizeof(st));
Run Code Online (Sandbox Code Playgroud)
File.read(reinterpret_cast<char *> (&st), sizeof(student));
if(st.retrollno()==n)
    {
    st.showdata();
    cout<<"\n\nPlease Enter The New Details of student"<<endl;
        st.getdata();
            int pos=(-1)*static_cast<int>(sizeof(st));
            File.seekp(pos,ios::cur);
            File.write(reinterpret_cast<char *> (&st), sizeof(student));
            cout<<"\n\n\t Record Updated";
            found=true;
    }
Run Code Online (Sandbox Code Playgroud)

c++ pointers static-cast reinterpret-cast

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