我正在使用microsoft visual c ++ 2010我可以使用boost库还是需要不同的编译器?
关于boost-asio多线程程序,我无法成功.
由于没有任何关于此的好例子或文档,我希望得到你的帮助:)
简单地说,我认为这段代码可以监听,但是当我想要"缓存"缓冲数据时,它不会打印任何内容或者只听一次并停止.
我的代码是:
void Worker::startThread(int clientNumber) {
cout << "listening: "<< clients[clientNumber]->port << endl;
boost::asio::io_service io_service;
tcp::acceptor acc(io_service, tcp::endpoint(tcp::v4(),portNumber[clientNumber]));
socket_ptr sock(new tcp::socket(io_service));
acc.accept(*sock);
try
{
for (;;) {
char data[max_length];
boost::system::error_code error;
cout << "message?" << endl;
size_t length = sock->read_some(boost::asio::buffer(data), error);
cout << "message :)" << endl;
cout << data << endl;
if(error == boost::asio::error::eof)
break; // Connection closed cleanly by peer.
else if (error)
throw boost::system::system_error(error); // Some other error.
}
}
catch (std::exception& e)
{
std::cerr …Run Code Online (Sandbox Code Playgroud) 你能解释一下这些选项在下面的g ++命令中构建boost.python对象的含义吗?
# location of the Python header files
PYTHON = /usr/include/python2.7
# location of the Boost Python include files and library
BOOST_INC = /usr/include
BOOST_LIB = /usr/lib
# compile mesh classes
TARGET = ex1
$(TARGET).so: $(TARGET).o
g++ -shared -Wl,--export-dynamic \
$(TARGET).o -L$(BOOST_LIB) -lboost_python \
-L/usr/lib/python2.7/config -lpython2.7 \
-o $(TARGET).so
$(TARGET).o: $(TARGET).c
g++ -I$(PYTHON) -I$(BOOST_INC) -c $(TARGET).c
Run Code Online (Sandbox Code Playgroud)
做什么:
意思?
我应该学习哪些其他概念来充分利用gcc/g ++编译器以及构建实用程序?编辑:我不需要所有这些,但最常用的功能是什么?
有没有更好的方法来确切地知道,我需要链接到构建所需的库?目前,我只能做猜测来弄清楚要链接的内容,即如果我使用Boost的日期时间库,我做了-lboost_date_time这样的事情,它只是起作用,但有时不适用于其他库.
另外,对于boost.python,我不想使用Bjam,因为它需要花费很多时间来学习,文档似乎含糊不清.make实用程序对我来说似乎更普遍.但是,有没有一个ide可以自动化构建过程,如Windows中的MSVS?代码::块?手动编写makefile比IDE管理的优点是什么?它似乎可以节省大量的构建自动化时间.
此代码正确获取selected_paths中指定的目录的内容,但前提是该目录为"C:".如果目录是"D:",则此代码将迭代我的应用程序的根目录(源文件所在的目录 - "D:\ excercizes\QT_projects\my_app").这是怎么回事?
QStringList my_app::extract_files_from_paths_(const QStringList& selected_paths)const
{
boost::filesystem3::path path;
QStringList result;
for (auto e : selected_paths)
{
boost::filesystem3::path path(e.toStdString().c_str());
if (boost::filesystem3::is_regular_file(path))
{
result.append(e);
}
else if (boost::filesystem3::is_directory(path) && !boost::filesystem3::is_empty(path))
{
std::vector<boost::filesystem3::path> paths_;
/*add everything from this path*/
std::copy(boost::filesystem3::directory_iterator(path), boost::filesystem3::directory_iterator(), // directory_iterator::value_type
std::back_inserter(paths_));
QStringList list_of_files;
for(auto e : paths_)
{
list_of_files.append(QString(e.string().c_str()));
}
return extract_files_from_paths_(list_of_files);
}
}
return result;
}
Run Code Online (Sandbox Code Playgroud) 我理解我的问题没有正确的答案,但这里是:
程序员应该知道哪些是最常见/最重要的提升库.我的意思是让你在简历上写"提升"的必备品
正如我所说,许多提升库都包含在c ++ 11标准中.更改boost::为std::I 之后我设法使用c ++ 11编译器编译它们.我有问题编译包含的代码boost::signals.
#include <iostream>
#include <functional>
#include <csignal>
void func()
{
std::cout << "Hello world" << std::endl;
}
int main()
{
std::signal<void()> s;
s.connect(func);
s();
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
prog.cpp: In function ‘int main()’:
prog.cpp:12:19: error: invalid operands of types ‘void (*(int, __sighandler_t)throw ())(int) {aka void (*(int, void (*)(int))throw ())(int)}’ and ‘void’ to binary ‘operator<’
std::signal<void()> s;
^
prog.cpp:12:22: error: ‘s’ was not declared in this scope
std::signal<void()> s;
Run Code Online (Sandbox Code Playgroud)
不std::signal等于 …
例:
boost::filesystem::path filename;
filename /= boost::filesystem::temp_directory_path();
filename /= boost::filesystem::unique_path();
Run Code Online (Sandbox Code Playgroud)
它比它更好吗?
auto filename = boost::filesystem::unique_path("%%%%-%%%%-%%%%-%%%%");
我需要帮助,我一直在同一台计算机上执行此操作,这意味着我已经安装了boost库,并且基于之前的代码,但这次它给了我错误:/tmp/ccpAYzPw.o:在函数`main' :
reading_data.cpp:(.text+0x356): undefined reference to `boost::program_options::options_description::m_default_line_length'
reading_data.cpp:(.text+0x361): undefined reference to `boost::program_options::options_description::m_default_line_length'
reading_data.cpp:(.text+0x3a6): undefined reference to `boost::program_options::options_description::options_description(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int)'
reading_data.cpp:(.text+0x3d3): undefined reference to `boost::program_options::options_description::add_options()'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'reading_data' failed
Run Code Online (Sandbox Code Playgroud)
我花了差不多2个小时看看发生了什么?但我无法理解为什么,所以我需要你的帮助.
这是我的代码,非常感谢你.
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream> // std::ifstream
#include <boost/program_options.hpp>
int main ()
{
boost::program_options::options_description desc("Allowed options");
desc.add_options()
("sign" , program_options::value<string>() -> default_value("gbm") ,"name of the input")
("week" , program_options::value<double>() -> default_value(1930) ,"number …Run Code Online (Sandbox Code Playgroud) 我们的想法是在C++中在运行时创建对象.
此创建的输入将是一个json文件.例如
{
"pi": 3.141,
"happy": true,
"name": "Niels",
"nothing": null,
"answer": {
"everything": 42
},
"list": [1, 0, 2],
"object": {
"currency": "USD",
"value": 42.99
}
}
Run Code Online (Sandbox Code Playgroud)
在C++中有什么选择?可以加强对此的帮助吗?
我想在不修改 .h 文件的情况下访问私有成员。这是 .h 文件的示例
class X
{
private:
class A
{...};
vector<A> arr;
}
Run Code Online (Sandbox Code Playgroud)
问:如何访问 X::arr ?
class X
{
private:
int a;
};
template<typename Tag, typename Tag::type Member>
struct XAccessor
{
friend typename Tag::type get(Tag)
{
return Member;
}
};
struct X_A
{
typedef int X::* type;
friend type get(X_A);
};;
template struct XAccessor<X_A, &X::a>;
...
auto x = new X;
x->*get(X_A())=11;
...
Run Code Online (Sandbox Code Playgroud)
我在网上找到了这种方法,但是当我更改typedef int X::* type为时typedef vector<X::A> X::* type,它给了我一个错误,说X::A无法访问。