0

我从在线教程中获得了一些 C++ Boost 代码。每个路径都以一种格式声明。

有没有办法包含 Visual Studio 来为 who 项目添加一个前缀,允许我 #include 该格式的文件?

它是一个接一个的头文件,它们都引用了该格式的更多头文件。

我知道 QT Creator 有一个 #INCLUDEPATHS 选项,它允许您导入一个目录,然后直接从中引用。

任何帮助将非常感激。

#include <boost\asio.hpp>
using namespace boost;

class SimpleSerial
{
public:
/**
 * Constructor.
 * \param port device name, example "/dev/ttyUSB0" or "COM4"
 * \param baud_rate communication speed, example 9600 or 115200
 * \throws boost::system::system_error if cannot open the
 * serial device
 */
SimpleSerial(std::string port, unsigned int baud_rate)
: io(), serial(io,port)
{
    serial.set_option(boost::asio::serial_port_base::baud_rate(baud_rate));
}

/**
 * Write a string to the serial device.
 * \param s string to write
 * \throws boost::system::system_error on failure
 */
void writeString(std::string s)
{
    boost::asio::write(serial,boost::asio::buffer(s.c_str(),s.size()));
}

/**
 * Blocks until a line is received from the serial device.
 * Eventual '\n' or '\r\n' characters at the end of the string are removed.
 * \return a string containing the received line
 * \throws boost::system::system_error on failure
 */
std::string readLine()
{
    //Reading data char by char, code is optimized for simplicity, not speed
    using namespace boost;
    char c;
    std::string result;
    for(;;)
    {
        asio::read(serial,asio::buffer(&c,1));
        switch(c)
        {
            case '\r':
                break;
            case '\n':
                return result;
            default:
                result+=c;
        }
    }
}

private:
boost::asio::io_service io;
boost::asio::serial_port serial;
};
4

1 回答 1

2

单击菜单栏中的“项目”,然后选择“属性...”。然后使用菜单树转到“配置属性”/“C/C++”/“常规”并将目录添加到“附加包含目录”。

于 2013-03-19T14:59:37.127 回答