我想解析Linux中的cpu信息。我寫了這樣的代碼:C++中的正則表達式11
// Returns full data of the file in a string
std::string filedata = readFile("/proc/cpuinfo");
std::cmath results;
// In file that string looks like: 'model name : Intel ...'
std::regex reg("model name: *");
std::regex_search(filedata.c_str(), results, reg);
std::cout << results[0] << " " << results[1] << std::endl;
但它返回空字符串。怎麼了?
難道你不是指'cmatch'?你可以發佈整個代碼和'cpuinfo'的內容嗎? – slaphappy 2012-08-08 10:01:49
看到此主題「regex_match和regex_search之間的區別?」 (http://stackoverflow.com/questions/11628047/difference-between-regex-match-and-regex-search) – SChepurin 2012-08-08 10:44:02
想要補充的是,它在VC++ 2010中的工作原理,由James Kanze在下面的答案中糾正了表達式。 – SChepurin 2012-08-08 10:59:19