我即将用C++编写程序,但我不确定如何去做.我想创建一个程序,可以与命令行前端一起使用,但也可以使用GUI前端,因为我不想将用户绑定到特定的接口,例如依赖项的小部件工具包.
怎么做最好的方法呢?我知道像RSync和SSH这样的程序在GUI中有前端,但我不确定如何做到这一点.拥有一个只使用system()来运行它的程序,同时拥有一个漂亮的GUI,这不是很麻烦吗?
我有一个无聊的功能来运行,我想循环它以节省这个时间(我有所有的数据),但它需要类型.有没有办法制作一个类型的数组,或有一些完成时间的事情来做到这一点?(如果它有帮助,我有3种类型,并希望针对所有类型运行所有类型的方法).
fprintf(stdout, "Testing UTF-32...\n");
testUTF<uint32_t, uint32_t>(&testEncs[0], &testEncs[0]);
testUTF<uint32_t, uint16_t>(&testEncs[0], &testEncs[1]);
testUTF<uint32_t, uint8_t> (&testEncs[0], &testEncs[2]);
fprintf(stdout, "Testing UTF-16...\n");
testUTF<uint16_t, uint32_t>(&testEncs[1], &testEncs[0]);
testUTF<uint16_t, uint16_t>(&testEncs[1], &testEncs[1]);
testUTF<uint16_t, uint8_t> (&testEncs[1], &testEncs[2]);
fprintf(stdout, "Testing UTF-8...\n");
testUTF<uint8_t, uint32_t>(&testEncs[2], &testEncs[0]);
testUTF<uint8_t, uint16_t>(&testEncs[2], &testEncs[1]);
testUTF<uint8_t, uint8_t> (&testEncs[2], &testEncs[2]);
Run Code Online (Sandbox Code Playgroud) 我正在使用CMake,我想尝试制作它,所以我有一个子目录,而不是通过我的项目或它的根目录分散的文件.
我有一个目录布局project/cmake/CMakeLists.txt和project/bin和project/source,所以如果他们想人们可以很容易地取出CMake的东西.我唯一的问题是可能有一种方法可以做到这一点,我不知道.目前它会生成一堆垃圾,包括一个project/cmake/bin/obtap.dir/home/jookia/Programming/obtap/source文件夹.
cmake_minimum_required(VERSION 2.6)
project(obtap)
add_definitions(-g -Wall)
add_executable(../bin/obtap ../source/main.cpp)
Run Code Online (Sandbox Code Playgroud)
它编译好,它输出正确的目录.但我的问题是这样的:有没有办法删除project/cmake/bin目录,并且可选地,有没有办法不拥有所有的CMake东西,而只是生成一个makefile,所以我有两个文件,CMakeLists.txt和Makefile?
char buffer[12] = {"Testing! 12"};
unsigned long compressedSize;
char* compressed = compress(buffer, 12, &compressedSize);
...
char* compress(char* buffer, unsigned long size, unsigned long* compressedSize)
{
Bytef* inBuffer = reinterpret_cast<Bytef*>(buffer);
uLong inSize = static_cast<uLong>(size);
Bytef* outBuffer = 0;
uLong outBufferSize = compressBound(inSize);
int error = compress2(outBuffer, &outBufferSize, inBuffer, inSize, 6);
if(error != Z_OK)
{
switch(error)
{
case Z_MEM_ERROR:
std::cerr << "Memory error!" << std::endl;
break;
case Z_BUF_ERROR:
std::cerr << "Buffer error!" << std::endl;
break;
default:
std::cerr << "Unknown error: " << …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
#include <memory>
int main(void)
{
std::shared_ptr<int> currInt(nullptr);
std::shared_ptr<int> newInt(new int);
currInt = newInt;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
事实证明,这不是有效的C++ 11(它用于草稿版本),并且赋值构造函数现在使用移动语义.我不明白的东西.
有人可以解释我是如何修改上面的代码使它...工作?
我有以下代码,其中Boost.Local使用函数回调来加载mo文件.这个函数对我来说叫做findMo,我试图将它绑定到一个对象,这样我就可以保留我放在moFinder的私有成员中的副作用.
class moFinder
{
public:
moFinder(string const& wantedFormat)
: format(wantedFormat)
{
// ...
}
std::vector<char> findMo(std::string const& filePath, std::string const& encoding)
{
// ...
}
};
std::locale createLocale(string const& name, string const& customTranslation,
string const& path, string const& domain, string const& pathFormat)
{
// ...
namespace blg = boost::locale::gnu_gettext;
blg::messages_info info;
info.paths.push_back(path);
info.domains.push_back(blg::messages_info::domain(domain));
moFinder finder(pathFormat);
blg::messages_info::callback_type callbackFunc;
callbackFunc = boost::bind(moFinder::findMo, boost::ref(finder));
info.callback = callbackFunc;
// ...
}
Run Code Online (Sandbox Code Playgroud)
编译时我收到以下错误:
错误:无效使用非静态成员函数'std :: vector moFinder :: findMo(const std :: string&,const std :: string&)' …
typedef unsigned char uChar;
typedef signed char sChar;
typedef unsigned short uShort;
typedef signed short sShort;
typedef unsigned int uInt;
typedef signed int sInt;
typedef unsigned long uLong;
typedef signed long sLong;
Run Code Online (Sandbox Code Playgroud)
我有一个typedef列表所以当我定义变量时,我可以准确.例如,如果我只需要数字0-5,我就会使用uChar.但我正在使用C++并正在制作引擎.我正在阅读关于.NET占用X字节的布尔值,并且由于内存对齐,它使用整数更快.
由于内存对齐,性能等原因,是否有理由使用int而不是uChar?
struct findCategoryByName
{
string name;
bool operator()(const category& a)
{
return (a.name == name);
}
};
struct findEntryByName
{
string name;
bool operator()(const entry* a)
{
return (a->name == name);
}
};
Run Code Online (Sandbox Code Playgroud)
有没有办法使用模板元编程或其他东西?如果有帮助,我总是可以使用指针使其成为类别*.
c++ ×6
backend ×1
boost ×1
boost-bind ×1
c++11 ×1
cmake ×1
frontend ×1
indentation ×1
optimization ×1
shared-ptr ×1
templates ×1
vim ×1
zlib ×1