可能重复:
如何摆脱deprecated conversion from string constant to ‘char*’海湾合作委员会的警告?
这项任务:
char *pc1 = "test string";
Run Code Online (Sandbox Code Playgroud)
给了我这个警告:
警告:不推荐将字符串常量转换为'char*'
虽然这个似乎很好:
char *pc2 = (char*)("test string");
Run Code Online (Sandbox Code Playgroud)
这是一个真正更好的方法吗?
注意:由于其他原因我不能使用const char*.
我想使用bjam使用两个不同的编译器MinGW和Visual C++ 2010 Express来构建boost:
bjam toolset=gcc,msvc variant=release link=static,shared threading=multi install
Run Code Online (Sandbox Code Playgroud)
问题是我没有bjam.我在Boost目录中找不到它,而我从其他地方下载的那个版本是错误的.
我应该能够从Boost中的代码构建它,但是如何?我读过我必须build.bat从BOOST_ROOT/tools/jam/src目录启动,但该目录不存在!
谢谢!
更新:
我已经能够获得bjam: bootstrap.bat gcc
然后,使用前面的参数启动bjam,我只获得MinGW(.dll和.a)的库.
这是我得到的关于Visual C++ 10的错误消息的摘录:
...
call "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 >nul
cl /Zm800 -nologo @"bin.v2\libs\test\build\msvc-10.0\release\asynch-exceptions-on\threading-multi\plain_report_formatter.obj.rsp"
...failed compile-c-c++ bin.v2\libs\test\build\msvc-10.0\release\asynch-exceptions-on\threading-multi\plain_report_formatter.obj...
...
...skipped <pbin.v2\libs\test\build\msvc-10.0\release\asynch-exceptions-on\threading-multi>boost_unit_test_framework-vc100-mt-1_48.dll for lack of <pbin.v2\libs\test\build\msvc-10.0\release\asynch-exceptions-on\threading-multi>compiler_log_formatter.obj...
...
common.mkdir bin.v2\libs\thread\build\msvc-10.0\release\threading-multi
common.mkdir bin.v2\libs\thread\build\msvc-10.0\release\threading-multi\win32
compile-c-c++ bin.v2\libs\thread\build\msvc-10.0\release\threading-multi\win32\thread.obj
\Microsoft was unexpected at this time.
...
call "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 >nul
cl /Zm800 …Run Code Online (Sandbox Code Playgroud) 我正在写一个记录器.如果禁用,这是定义LOG宏的代码:
#ifdef NO_LOG
#include <ostream>
struct nullstream : std::ostream {
nullstream() : std::ios(0), std::ostream(0) {}
};
static nullstream logstream;
#define LOG if(0) logstream
#endif
LOG << "Log message " << 123 << std::endl;
Run Code Online (Sandbox Code Playgroud)
它工作正常.编译器应该完全删除与LOG宏相关的代码.
但是我想避免包含ostream并将logstream对象定义为真正"轻"的东西,可能为null.
谢谢!
我有一些Microsoft代码(XLCALL.CPP),我试图用CodeBlocks/MinGW编译.
在这一行,我得到一个编译时错误:
__forceinline void FetchExcel12EntryPt(void)
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误消息:
XLCALL.CPP | 36 |错误:'void'之前的预期构造函数,析构函数或类型转换
此错误是预期的,因为__forceinline是Microsoft特定的语言添加,但未被GCC识别.
因此,为了编译,我尝试在CodeBlocks中添加thiese定义(项目构建选项/编译器设置/ #define):
#define __forceinline inline
#define __forceinline
Run Code Online (Sandbox Code Playgroud)
但是我仍然得到同样的错误.
如果在对话框中我没有指定#define预处理器命令(即:)__forceinline inline,这就是我得到的:
XLCALL.CPP | 36 |错误:数字常量之前的预期unqualified-id
有没有办法编译这样的代码,而不使用 Visual C++?
是否可以定义静态插入操作符,该操作符仅对类的静态成员进行操作?就像是:
class MyClass
{
public:
static std::string msg;
static MyClass& operator<< (const std::string& token) {
msg.append(token);
return *this; // error, static
}
};
Run Code Online (Sandbox Code Playgroud)
或者:
static MyClass& operator<< (MyClass&, const std::string &token)
{
MyClass::msg.append(token);
return ?;
}
Run Code Online (Sandbox Code Playgroud)
这就是我想用它的方式:
MyClass << "message1" << "message2";
Run Code Online (Sandbox Code Playgroud)
谢谢!
是否可以在不使用平台特定功能的情况下打印UTF-8字符串?
#include <iostream>
#include <locale>
#include <string>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
wcout.imbue(locale("en_US.UTF-8")); // broken on Windows (?)
wstring ws1 = L"Wide string.";
wstring ws2 = L"Wide string with special chars \u20AC"; // Euro character
wcout << ws1 << endl;
wcout << ws2 << endl;
wcout << ws1 << endl;
}
Run Code Online (Sandbox Code Playgroud)
我收到此运行时错误:
在抛出'std :: runtime_error'的实例后调用终止
what():locale :: facet :: _ S_create_c_locale名称无效
如果我删除该行wcout.imbue(locale("en_US.UTF-8"));,我只会ws1打印一次.
在另一个问题(" 我怎么能cin和cout一些unicode文本? ")中,Philipp写道:"wcin和wcout在Windows上不起作用,就像等效的C函数一样.只有原生API可以工作." MinGW也是真的吗?
谢谢你的提示!
平台:
MinGW/GCC
Windows 7