我一直在使用sscanf,我觉得我已经太熟悉了.显然它也被弃用了,我应该使用sscanf_s,据我所知,这不是标准.所以我想知道STL是否有一个惯用的C++替代品做同样的事情?
谢谢
我做:
sscanf(it->second->c_str(),"%d %f %f %f %f %f %f %d \" %[^\"] \" \" %[^\"]",
&level, &x, &y, &angle, &length, &minAngle, &maxAngle, &relative, name,parentName);
Run Code Online (Sandbox Code Playgroud)
dee*_*see 11
格式化并不容易,但请查看stringstream.又见istringstream以及ostringstream输入和输出缓冲器格式.
xDD*_*xDD 10
在C++中,终极解析器是Boost.Qi
#include <boost/spirit/include/qi.hpp>
#include <string>
namespace qi = boost::spirit::qi;
int main()
{
int level, relative;
float x, y, angle, length, minAngle, maxAngle;
std::string name, parentName;
std::string input = "20 1.3 3.7 1.234 100.0 0.0 3.14 2 \"Foo\" \"Bar\"";
std::string::iterator begin = input.begin();
std::string::iterator end = input.end();
using qi::int_;
using qi::float_;
using qi::char_;
using qi::lit;
using qi::ascii::space;
qi::phrase_parse(begin, end,
int_ >> float_ >> float_ >> float_ >> float_ >> float_ >> float_ >> int_
>> lit("\"") >> *(~char_('"')) >> lit("\"")
>> lit("\"") >> *(~char_('"')) >> lit("\""),
space,
level, x, y, angle, length, minAngle, maxAngle, relative, name, parentName);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17577 次 |
| 最近记录: |