小编Joe*_*ath的帖子

编写跨平台C++代码(Windows,Linux和Mac OSX)

这是我第一次尝试在C++中编写任何稍微复杂的东西,我正在尝试构建一个可以从Objective-C和.NET应用程序接口的共享库(好的,那部分后来......)

我的代码是 -

#ifdef TARGET_OS_MAC
  // Mac Includes Here
#endif

#ifdef __linux__
  // Linux Includes Here
  #error Can't be compiled on Linux yet
#endif

#ifdef _WIN32 || _WIN64
  // Windows Includes Here
  #error Can't be compiled on Windows yet
#endif

#include <iostream>

using namespace std;

bool probe(){
  #ifdef TARGET_OS_MAC
    return probe_macosx();
  #endif
  #ifdef __linux__
    return probe_linux();
  #endif
  #ifdef _WIN32 || _WIN64
    return probe_win();
  #endif
}

bool probe_win(){
  // Windows Probe Code Here
  return true;
}

int main(){

  return 1;
} …
Run Code Online (Sandbox Code Playgroud)

c++ cross-platform

35
推荐指数
3
解决办法
6万
查看次数

如何在没有错误的情况下退出X11程序

在问题结束时,我在X11中有一个相当简单的"Hello World".但是当它退出时,我得到下面的运行时错误消息:

$ ./xtest
XIO:  fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
      after 9 requests (7 known processed) with 0 events remaining.
Run Code Online (Sandbox Code Playgroud)

所以我试着处理wmDeleteMessage自己,我能够阻止窗口关闭,所以我知道我正确地得到了这个事件.比我添加了一个XDestroyWindow()事件处理,我得到了新的错误.

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  4 (X_DestroyWindow)
  Resource id in failed request:  0x130
  Serial number of failed request:  12
  Current serial number in output stream:  12
Run Code Online (Sandbox Code Playgroud)

听起来我正试图摧毁已经被摧毁的窗口,但是如果我把XDestroyWindow()它取出它在我的屏幕上保持活着.

下面是我的代码,试图破坏窗口处理程序.如何在没有任何错误的情况下退出?

#include<X11/Xlib.h>
#include <iostream>

int main()
{
  Display *display;
    if(!(display=XOpenDisplay(NULL))) 
    { …
Run Code Online (Sandbox Code Playgroud)

c++ linux x11 xlib

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

逗号运算符在赋值期间如何工作?

int a = 1;
int b = (1,2,3);
cout << a+b << endl; // this prints 4
Run Code Online (Sandbox Code Playgroud)
  1. (1,2,3)c ++中的某种结构(某种原始类型的列表,也许?)
  2. 为什么b分配值3?编译器是否只是从列表中取出最后一个值?

c

9
推荐指数
2
解决办法
2657
查看次数

如何将PDF文档的所有页面移动一英寸?

我想将现有pdf文档的所有页面都移动一英寸,这样它们就可以打三孔而不会打到内容.将生成pdf文档,因此无法更改生成方式.

似乎iText可以从之前的问题中做到这一点.

什么是C++或Python的等效库(或者这样做)?

如果它是依赖于平台的,我需要一个适用于Linux的工具.

更新:想我会发布一个我编写的小脚本,以防万一其他人找到这个页面并需要它.

工作代码归功于Scott Anderson的建议:

rightshift.py

#!/usr/bin/python2
import sys
import os
from  pyPdf import PdfFileReader, PdfFileWriter

#not sure what default user space units are. 
# just guessed until current document i was looking at worked
uToShift = 50;

if (len(sys.argv) < 3):
  print "Usage rightshift [in_file] [out_file]"
  sys.exit()

if not os.path.exists(sys.argv[1]):
  print "%s does not exist." % sys.argv[1]
  sys.exit()

pdfInput = PdfFileReader(file( sys.argv[1], "rb"))
pdfOutput = PdfFileWriter()

pages=pdfInput.getNumPages()

for i in range(0,pages):
  p = pdfInput.getPage(i) …
Run Code Online (Sandbox Code Playgroud)

c++ python linux pdf pypdf

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

谁应该了解对方?

我总是对谁应该了解对方感到困惑.

例如:

Circle.Draw(&canvas) 要么 Canvas.Draw(&circle)

要么 Draw(&canvas, &circle)

EmployeeVector.Save(&file) 要么 File.Save(&employee_vector)

甚至还是

  void operator() (Employee e) { Save( e.Serialize();}
  for_each(employees.begin(), employees.end(),File)
Run Code Online (Sandbox Code Playgroud)

我想我最终"抽象"了太多,我有各种适配器,所以没有人知道任何人.

c++ oop

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

英特尔编译器与GCC

当我使用英特尔编译器编译应用程序时,它比我用GCC编译它时要慢.英特尔编译器的输出速度慢了2倍.该应用程序包含几个嵌套循环.GCC和我缺少的英特尔编译器之间是否存在任何差异?我是否需要打开其他一些标志来提高英特尔编译器的性能?我预计英特尔编译器的速度至少与GCC一样快.

编译器版本:

 Intel version  12.0.0 20101006 
 GCC   version  4.4.4  20100630

编译器标志与两个编译器相同:

-O3 -openmp -parallel -mSSE4.2 -Wall -pthread
Run Code Online (Sandbox Code Playgroud)

c++ compiler-construction optimization gcc intel

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

如何从powerbuilder11.5调用win32 dll?

我用c ++编写了这段代码:

extern "C" __declspec(dllexport)    int __stdcall sumx(int a, int b)
{
  int result;

  result = a + b;

  return result;
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

int __stdcall sumx(int a, int b)
{
  int result;

  result = a + b;

  return result;
}
Run Code Online (Sandbox Code Playgroud)

并构建win32 DLL.然后将其复制到PB目录中.

在此输入图像描述

我定义它的外部功能.

在此输入图像描述

我称之为:

在此输入图像描述

当我运行它:

在此输入图像描述

为什么会出现错误?TNX

c++ powerbuilder winapi

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