小编Rob*_*obᵩ的帖子

使C函数指针在C++中使用基于C风格的堆栈调用机制

我想在我的C++程序中从一个dll调用一个纯C风格的函数.我尝试使用reinterpret_castto来转换我的函数指针,__cdecl并且仍然保持调用约定_stdcall.我是Windows C++编程的新手.

从评论中编辑代码

reinterpret_cast< Error ( __cdecl*)(int,int)> (GetProcAddress(Mydll::GetInstance()->ReturnDLLInstance(), "add"))(1,10) 
Run Code Online (Sandbox Code Playgroud)

是我的电话.实际的函数语法似乎已声明为

Error __cdecl add(int,int);
Run Code Online (Sandbox Code Playgroud)

调试器抛出错误运行时检查失败#0.我在Windows-C++工作

c c++ pointers function visual-c++

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

使用具有浮动类型的bitset

你有浮动数据类型的bitset容器吗?例:

bitset<sizeof(float)*sizeof(char)> second(5.5f);
cout << second.to_string() << endl;
Run Code Online (Sandbox Code Playgroud)

它无法正常工作.我想要做的是获得位代表.

c++ floating-point bitset

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

将一些C++位操作转换并解释为C#

你能帮我翻译一下这个第三方API方法的c#:

我也不理解位操作中发生的一切.

inline void SetBits(unsigned long& aValue,unsigned int aData,unsigned int aPosition,unsigned int aLength)
{
    unsigned int datamask;   // data mask, before aPosition shift

    if (aLength == 32)
        datamask = 0xFFFFFFFF;
    else
        datamask = (1L << aLength) - 1;

    aValue &= ~(datamask << aPosition);             // Clear bits
    aValue |= (aData & datamask) << aPosition;      // Set value
}
Run Code Online (Sandbox Code Playgroud)

我在C#版本中收到此错误:

错误运算符'<<'不能应用于'long'和'uint'类型的操作数

错误运算符'<<'不能应用于'uint'和'uint'类型的操作数

编辑:

我认为这个解决方案没问题:

    private void SetBits(ref uint value, uint data, int position, int length)
    {
        uint datamask;   // data mask, before …
Run Code Online (Sandbox Code Playgroud)

c# c++ bit-manipulation

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

根据模式加入行

我有以下文件:

test
1
My
2
Hi
3
Run Code Online (Sandbox Code Playgroud)

我需要一种方法来使用cat,grep或awk来提供以下输出:

test1
My2
Hi3
Run Code Online (Sandbox Code Playgroud)

我怎样才能在一个命令中实现这一目标?就像是

cat file.txt | grep ... | awk ...
Run Code Online (Sandbox Code Playgroud)

请注意,它始终是一个字符串,后跟原始文本文件中的数字.

bash shell scripting solaris

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

getifaddrs给我重复的网络接口地址吗?

我正在寻找一个特定的网络地址使用一个小片段,如:

  char name[INET_ADDRSTRLEN];
  struct ifaddrs *iflist;
  if (getifaddrs(&iflist) < 0)
    perror("getifaddrs");

  struct in_addr addr;
  for (struct ifaddrs *p = iflist; p; p = p->ifa_next)
    {
      if (strcmp(p->ifa_name, "lo") == 0)
        {
          addr = reinterpret_cast<struct sockaddr_in*>(p->ifa_addr)->sin_addr;
          if (inet_ntop(AF_INET, &addr, name, sizeof(name)) == NULL)
            {
              perror("inet_ntop");
              continue;
            }

          cout << name << " ---> " << if_nametoindex("lo") << " : " << addr.s_addr << endl;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我得到的输出是:

1.0.0.0 ---> 1 : 1
127.0.0.1 ---> 1 : 16777343
Run Code Online (Sandbox Code Playgroud)

我不明白第一个结果..这不会发生在类似eth#的东西上,但它与另一个名为bond0的接口有关.这是什么?

c++ network-programming

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

C++函数参数创建类

说我有以下课程:

class A
{
public:
    A() {
    }

    A(int a):_a(a){
    }

    int _a;
};
Run Code Online (Sandbox Code Playgroud)

并具有以下功能:

void someFunc (A a)
{
    cout << a._a;
}
Run Code Online (Sandbox Code Playgroud)

所以程序中的以下行正常工作:

someFunc (5); // Calls A(int a) Constructor.
Run Code Online (Sandbox Code Playgroud)

但以下不是:

someFunc(); //Compile error
Run Code Online (Sandbox Code Playgroud)

可以预期,如果它在获取整数时可以构建A,为什么不使用默认构造函数构建一个,当没有参数调用时?

c++

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

在C++中输出ascii表

码:

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

class Ascii_output {
public:
    void run() {
        print_ascii();
    }
private:
    void print_ascii() {
        int i, j;                                                           // i is         used to print the first element of each row
                                                                        // j is used to print subsequent columns of a given row
    char ch;                                                            // ch stores the character which is to be printed
    cout << left;

    for (i = 32; i < 64; i++) {                                         // 33 rows are printed out (64-32+1)
        ch …
Run Code Online (Sandbox Code Playgroud)

c++ windows ascii iostream char

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

当抛出异常指针时,为什么我应该通过引用使用catch

通过引用捕获异常时,我得到的唯一好处是避免使用异常对象的副本?基本上是区别

try
{
    CString a_csSQL = _T("SELECT * FROM Library");
    CDatabase aDB;
    aDB.OpenEx(g_csConnectionStringWdDSN,CDatabase::noOdbcDialog));
    aDB.ExecuteSQL(a_csSQL);
}
catch(CDBException *& ex)
{
    ex->Delete();
}
Run Code Online (Sandbox Code Playgroud)

try
{
    CString a_csSQL = _T("SELECT * FROM Library");
    CDatabase aDB;
    aDB.OpenEx(g_csConnectionStringWdDSN,CDatabase::noOdbcDialog))
    aDB.ExecuteSQL(a_csSQL);
}
catch(CDBException * ex)
{
    ex->Delete();
}
Run Code Online (Sandbox Code Playgroud)

c++ mfc exception visual-c++

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

pandas dataframe中max值的索引和列

我有一个python数据帧df,有五列五行.我想获得最多三个值的行和列名称

例:

df = 

  A   B  C  D  E  F
1 00 01 02 03 04 05
2 06 07 08 09 10 11
3 12 13 14 15 16 17
4 18 19 20 21 22 23
5 24 25 26 27 28 29
Run Code Online (Sandbox Code Playgroud)

输出显示类似[5,F],[5,E],[5,D]的内容

python pandas

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

删除你的JSON数据

我是python的新手,似乎我的所有JSON数据都与u'前缀结合在一起:

{u'number': u'12345666', u"items"...}
Run Code Online (Sandbox Code Playgroud)

我不需要这些数据(unicode或其他),因为我想将字符串打印到Javascript变量中:

var obj = data; // data is the object above.
Run Code Online (Sandbox Code Playgroud)

我的python看起来像这样;

index.html:
var obj = ${data};
Run Code Online (Sandbox Code Playgroud)

我正在使用moko框架进行模板化.

// getitems() return {'number':'12312...}
context = {'data': getitems(self)}
self.render_response('index.html',**context)
Run Code Online (Sandbox Code Playgroud)

处理过的javascript输出数据如下所示:

var obj = {u'number': u'12345666', u"items"...} 
Run Code Online (Sandbox Code Playgroud)

这是我的问题.

javascript python json

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