我正在使用它steady_clock来保存某些消息的时间戳.对于调试目的,可以使用日历(或类似的东西).
对于其他时钟,这是静态功能to_time_t,但在GCC(MinGW 4.8.0)上,此功能不存在.
现在我打印的东西像:
Timestamp: 26735259098242
Run Code Online (Sandbox Code Playgroud)
对于时间戳我需要一个steady_clock所以我不能使用system_clock或其他人.
编辑
上一个打印是从time_since_epoch().count()给出的
是否有一些情况我不得不喜欢二进制文件到文本文件?我使用C++作为编程语言?
例如,如果我要存储一些大文本文件,最好是使用文本文件还是二进制文件?
编辑
目前的文件没有要求人类可读的要求.有些性能差异,安全性差异等等?
编辑
很抱歉省略其他要求(感谢Carey Gregory)
我在C++中使用Eclipse Keplero.我有一个依赖于其他共享库的项目.
要调试应用程序,我要添加manully所有依赖库,但这很无聊.所以我认为我可以从"运行配置"中的"环境"更新PATH环境变量.我添加了以下变量:
PATH:${PATH};${workspace_loc}\library\lib\x64;${BOOST_X64_NATIVE}
BOOST_X64_NATIVE是一个os环境变量(Windows 7).但我有以下信息:Reference to undefined variable PATH.
那么如何在eclipse上设置正确的环境变量,我不必每次都复制所有依赖项.
我正在使用实际devel分支中的 Catch2,并且在尝试比较两个时出现链接器错误vector<string_view>
该问题可以重现如下:
#include <vector>
#include <string_view>
#include <catch2/catch_test_macros.hpp>
TEST_CASE("Can split string", "[split]") {
vector<string_view> splittedString = {"this is a string view"sv};
vector<string_view> EXPECTED = {"I'm"sv, "Elvis"sv,"Dukaj"sv};
REQUIRE(splittedString == EXPECTED);
}
Run Code Online (Sandbox Code Playgroud)
我的CMakeLists.txt:
find_package(Catch2 REQUIRED)
# ...
target_link_libraries(${PROJECT_NAME} PRIVATE Catch2::Catch2WithMain)
Run Code Online (Sandbox Code Playgroud)
尝试构建时出现以下链接器错误:
Catch2/src/catch2/../catch2/catch_tostring.hpp:126: error: undefined reference to `Catch::StringMaker<std::basic_string_view<char, std::char_traits<char> >, void>::convert[abi:cxx11](std::basic_string_view<char, std::char_traits<char> >)'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我错过了一些内容吗?
我需要一个用于调试目的的记录器,我正在使用Boost.Log(1.54.0和boost.org主页中的补丁).
一切都很好我已经创建了一些像这样的宏:
#define LOG_MESSAGE( lvl ) BOOST_LOG_TRIVIAL( lvl )
Run Code Online (Sandbox Code Playgroud)
现在这是一种只在调试模式下在BOOST_LOG_TRIVIAL(lvl)中显示LOG_MESSAGE(lvl)并在发布中忽略的方法吗?
例如:
LOG_MESSAGE( critical ) << "If I read this message we're in debug mode"
Run Code Online (Sandbox Code Playgroud)
编辑 我的第一次尝试是创建一个nullstream ...我认为在发布模式编译器将优化它...
#if !defined( NDEBUG )
#include <boost/log/trivial.hpp>
#define LOG_MESSAGE( lvl ) BOOST_LOG_TRIVIAL( lvl )
#else
#if defined( __GNUC__ )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-value"
#endif
#include <iosfwd>
struct nullstream : public std::ostream {
nullstream() : std::ios(0), std::ostream(0) {}
};
static nullstream g_nullstream;
#define LOG_MESSAGE( lvl ) g_nullstream
#if defined( __GNUC__ …Run Code Online (Sandbox Code Playgroud) 当我尝试使用原子的is_lock_free()方法时,我遇到了以下编译错误.
struct Simple1 { int i; };
struct Simple2 { int a; int b; };
struct Simple3 { int a; int b; int c; };
int main()
{
atomic< Counter > counter;
atomic< Param > param;
atomic< Simple1 > s1;
atomic< Simple2 > s2;
atomic< Simple3 > s3;
cout
<< "Is s1 lock free? " << boolalpha << s1.is_lock_free() << '\n'
<< "Is s2 lock free? " << boolalpha << s2.is_lock_free() << '\n'
<< "Is s3 lock free? " << …Run Code Online (Sandbox Code Playgroud) 如果我写了这行代码:
std::thread t(EchoServer(socket));
Run Code Online (Sandbox Code Playgroud)
编译器如何解释这条指令?它可以是函数声明,也可以只是初始化.我有跟随代码:
#include <iostream>
#include <thread>
#include <boost/asio.hpp>
#include <boost/asio.hpp>
typedef boost::asio::ip::tcp::socket Socket;
auto socket_deleter = [] (Socket* s) {s->close(); delete s;};
typedef std::unique_ptr<Socket, decltype(socket_deleter)> socket_ptr;
class EchoServer {
public:
static void Listen(unsigned int port)
{
using namespace std;
using namespace boost::asio;
io_service ios;
// create an endpoint to listen to a certain port
ip::tcp::endpoint endpoint(ip::tcp::v4(), port);
cout << "Listening to TCP Socket on port " << port << " ..." << endl;
// Start opening a socket …Run Code Online (Sandbox Code Playgroud) 我通常建议将警告视为错误.我正在使用Boost C++ 1.54.0和MinGW 4.8.1,特别是我正在使用ptree.
#include <iostream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这个简单的程序会导致以下错误:
typedef 'cons_element' locally defined but not used [-Wunused-local-typedefs] line 228, external location: \boost\tuple\detail\tuple_basic.hpp
typedef 'Str' locally defined but not used [-Wunused-local-typedefs] line 38, external location: \boost\property_tree\detail\xml_parser_write.hpp
typedef 'Str' locally defined but not used [-Wunused-local-typedefs] line 72, external location: \boost\property_tree\detail\xml_parser_write.hpp
typedef 'T_must_be_placeholder' locally defined but not used [-Wunused-local-typedefs] line 37, external …Run Code Online (Sandbox Code Playgroud) 我有以下源代码,用MinGW编译.但是当我尝试构建时,我遇到了编译类型错误:
main.cpp:11: error: expected type-specifier
using Iter = MyMap::iterator;
^
main.cpp:12: error: expected type-specifier
using CIter = MyMap::const_iterator;
^
Run Code Online (Sandbox Code Playgroud)
GCC以前期待一个说明者MyMap.但它期望哪个说明符呢?
#include <ctime>
#include <map>
template< typename T >
class MyClass
{
private:
class Inner {};
using MyMap = std::map< time_t, Inner >;
using Iter = MyMap::iterator;
using CIter = MyMap::const_iterator;
};
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud) 有没有办法获得符号链接的目标pathlib?我知道这可以用来完成os.readlink().
我想创建一个由链接及其目标文件组成的字典.
links = [link for link in root.rglob('*') if link.is_symlink()]
files = [Path(os.readlink(str(pointed_file))) for pointed_file in links]
Run Code Online (Sandbox Code Playgroud)
编辑 ...我想过滤所有不是绝对的路径
link_table = {link : pointed_file for link, pointed_file in zip(links, files) if pointed_file.is_absolute()}
Run Code Online (Sandbox Code Playgroud) 在数学中有不同类型的范围:它们可以是开放的((a,b)),关闭([a,b]),左开(a,b))或右开([a,b)).
我想在C++(而不是11)中编写一个模板函数,可以很容易地管理这些情况.但我对元编程和模板并不十分自信.
我想要这样的东西:
const int max = MAX, int min = MIN;
int x = value;
// check close range
if ( is_in_range( x, min, max ) ) //...
if ( is_in_range( x, min, max, open) ) //...
if ( is_in_range( x, min, max, left_open) ) //...
if ( is_in_range( x, min, max, right_open) ) //...
Run Code Online (Sandbox Code Playgroud)
有人有一些建议吗?
编辑1
我试过这个但是无法编译
enum { range_open, range_close, range_left_open, range_right_open };
namespace detail {
template < typename Type >
inline bool check_open_range( const Type& x, …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个可移植的 gcc,以允许其他人使用不同的系统进行编译。
我用crosstool-ng交叉编译gcc-8.2的x86_64,我建了一个静态的工具链。
我创建了以下工具链文件:
#set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
set(QAMF_ROOT "/opt/hyperserver-dev/x86_64-qamf")
set(COMPILER_ROOT "${QAMF_ROOT}")
set(COMPILER_PREFIX "x86_64-qamf-linux-gnu-")
set(C_COMPILER "gcc")
set(CXX_COMPILER "g++")
# specify the cross compile
set(CMAKE_C_COMPILER ${COMPILER_ROOT}/bin/${COMPILER_PREFIX}${C_COMPILER} )
set(CMAKE_CXX_COMPILER ${COMPILER_ROOT}/bin/${COMPILER_PREFIX}${CXX_COMPILER} )
# HyperServer sysroot path
set(HYPERSERVER_SYSROOT "${COMPILER_ROOT}/x86_64-qamf-linux-gnu/sysroot")
# where is the target environment
set(CMAKE_FIND_ROOT_PATH ${HYPERSERVER_SYSROOT} )
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Run Code Online (Sandbox Code Playgroud)
在我的主机上它工作得很好,我可以毫无问题地编译,但是当我在另一台机器上移动工具链文件时,我遇到了问题。如果我尝试在 cmake 中包含 Threads,则会出现以下错误: …
struct Node *addToEmpty(struct Node *last, int data)
{
// This function is only for empty list
if (last != NULL)
return last;
// Creating a node dynamically.
struct Node *temp =
(struct Node*)malloc(sizeof(struct Node));
// Assigning the data.
temp -> data = data;
last = temp;
// Creating the link.
last -> next = last;
return last;
}
struct Node *addBegin(struct Node *last, int data)
{
if (last == NULL)
return addToEmpty(last, data);
struct Node *temp =
(struct Node *)malloc(sizeof(struct …Run Code Online (Sandbox Code Playgroud)