我从在线教程中获得了一些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;
};
答案 0 :(得分:2)
单击菜单栏中的“项目”,然后选择“属性...”。然后使用菜单树转到“Configuration Properties”/“C / C ++”/“General”并将目录添加到“Additional Include Directories”。