小编jos*_*shu的帖子

std :: make_pair with c ++ 11

您好我有以下代码:

bool PinManager::insertPin(const std::string& p_pinNumber, const std::string& p_mode)
{
    boost::shared_ptr<GPIOPin> pin(new GPIOPin(p_pinNumber, p_mode));
    if (pin)
    {
        m_pinsInUse.insert(std::make_pair<std::string, boost::shared_ptr<GPIOPin> >(p_pinNumber, pin));
        return true;
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

这段代码总是被编译,但是当我添加-std=c++0x标志时,这段代码无法使用以下消息进行编译:

[ 42%] Building CXX object gpioaccess/CMakeFiles/gpioaccess.dir/pinmanager/pinmanager.cpp.o
/home/pi/robot_2.0/trunk/gpioaccess/pinmanager/pinmanager.cpp: In member function 'bool gpioaccess::PinManager::insertPin(const string&, const string&)':
/home/pi/robot_2.0/trunk/gpioaccess/pinmanager/pinmanager.cpp:39:101: error: no matching function for call to 'make_pair(const string&, boost::shared_ptr<gpioaccess::GPIOPin>&)'
/home/pi/robot_2.0/trunk/gpioaccess/pinmanager/pinmanager.cpp:39:101: note: candidate is:
/usr/include/c++/4.6/bits/stl_pair.h:262:5: note: template<class _T1, class _T2> std::pair<typename std::__decay_and_strip<_T1>::__type, typename std::__decay_and_strip<_T2>::__type> std::make_pair(_T1&&, _T2&&)
gpioaccess/CMakeFiles/gpioaccess.dir/build.make:77: recipe for target 'gpioaccess/CMakeFiles/gpioaccess.dir/pinmanager/pinmanager.cpp.o' failed
make[2]: *** [gpioaccess/CMakeFiles/gpioaccess.dir/pinmanager/pinmanager.cpp.o] …
Run Code Online (Sandbox Code Playgroud)

c++ gcc boost c++11 raspberry-pi

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

AWK 中的正则表达式

我正在尝试使用 awk 模式解析以下输入:

史密斯,吉姆 12.34

12.34 吉姆·史密斯

我有一个模式检查,看看第一个字段是否包含字母字符,第二个字段是否包含字母字符,第三个字段包含一个数字,第二个模式检查第二种情况,如下所示:

$1 ~ /[A-Za-z]/ && $2 ~ /[A-Za-z]/ && $3 ~ /[0-9]/{
do fun things with record
}
$3 ~ /[A-Za-z]/ && $2 ~ /[A-Za-z]/ && $1 ~ /[0-9]/
{
this is the second form of the record
}
Run Code Online (Sandbox Code Playgroud)

但是,我的程序似乎通过了两项检查并执行了两项操作。我一直试图找出我哪里搞砸了,但同样的事情不断发生。任何方向正确的观点都值得赞赏。我知道有很多方法可以做到这一点。我发现了其中一些,但我想具体知道我在这里做错了什么。

我正在使用 awk 运行 CentOS 7:

gawk --version
GNU Awk 4.0.2
Run Code Online (Sandbox Code Playgroud)

regex bash awk

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

如何在C/C++程序中加载内核模块

我正在使用 ds18b20 温度传感器,并且正在将一些 python 代码转换为 C++,以帮助更好地学习该语言。我遇到了一个问题,我需要加载 w1-gpio 和 w1-therm 模块。我在堆栈溢出上发现了很多内容,提到应该使用 init_module ,并且在同一个线程中,其他人提到要使用fork()side exec()。经过大量谷歌搜索和阅读手册页后,我找不到任何有关如何完成这些任务的示例。有人可以指出和/或举例说明如何使用这两种方法加载这两个模块吗?或者提供不涉及 system("modprobe w1-gpio") 的替代方案?

uname -a
Run Code Online (Sandbox Code Playgroud)

产生:

Linux raspberrypi 4.1.13-v7+ #826 SMP PREEMPT Fri Nov 13 20:19:03 GMT 2015 armv7l GNU/Linux
Run Code Online (Sandbox Code Playgroud)

c c++ python kernel-module raspberry-pi

2
推荐指数
1
解决办法
3420
查看次数

CUDA 程序产生意想不到的结果

我正在关注有关并行计算的 udacity 系列,该系列是在 nvidia 的学习 cuda 网站上找到的,第一个程序正在计算非常奇怪的结果。

这段代码只是简单地计算一个数字的立方,但是程序产生的输出是:

#include <stdio.h>

__global__ void cube(float * d_out, float * d_in){
    int idx = threadIdx.x;
    float f = d_in[idx];
    d_out[idx]  = f * f * f;
}

int main(int argc, char ** argv) {
    const int ARRAY_SIZE = 64;
    const int ARRAY_BYTES = ARRAY_SIZE * sizeof(float);
    // generate the input array on the host
    float h_in[ARRAY_SIZE];
    for (int i = 0; i < ARRAY_SIZE; i++) {
        h_in[i] = float(i);
    }
    float h_out[ARRAY_SIZE];

    // …
Run Code Online (Sandbox Code Playgroud)

cuda

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

原子变量从一个函数中多次访问

我有以下代码:

标题:

class Counter
{
public:
    Conuter(const std::string& fileName);
    boost::uint16_t getCounter();
private:
    tbb::atomic<boost::uint32_t> counter;
    std::string counterFileName;
};
Run Code Online (Sandbox Code Playgroud)

cpp:

Counter::Counter(const std::string& fileName) : counter(), counterFileName(fileName)
{  
    std::string line;
    std::ifstream counterFile (fileName.c_str());  
    if (counterFile.is_open())
    {
        getline (counterFile, line);
        counterFile.close();
    }

    boost::uint32_t temp = std::stoul (line,nullptr,0);
    counter = temp;
}

boost::uint32_t Counter::getCounter()
{
    if (counter > 1000)
    {
        counter = 0;
    }

    assert( counter < 1000);

    const boost::uint32_t ret = counter++;

    if ((counter % 10) == 0)
    {
        // write the counter back …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading boost tbb

-2
推荐指数
1
解决办法
63
查看次数

标签 统计

c++ ×3

boost ×2

raspberry-pi ×2

awk ×1

bash ×1

c ×1

c++11 ×1

cuda ×1

gcc ×1

kernel-module ×1

multithreading ×1

python ×1

regex ×1

tbb ×1