V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  j3399141  ›  全部回复第 1 页 / 共 1 页
回复总数  2
/*
需求随便改
*/
#include <iostream>
#include <regex>
#include <fstream>
#include <sstream>

int main(void)
{
try
{
std::fstream file("sample.in.txt", std::fstream::in);
std::stringstream stream;
stream << file.rdbuf();
file.close();

std::string input = stream.str();

std::regex pattern("answer=\"(.*?)\"");

std::sregex_token_iterator next(std::begin(input), std::end(input), pattern, 1);
std::sregex_token_iterator end;

std::vector<std::string> result;
while (next != end)
{
result.push_back(*next++);
}

copy(std::begin(result), std::end(result), std::ostream_iterator<std::string>(std::cout, "\n"));
std::vector<std::string>().swap(result);
}
catch (const std::exception& exception)
{
std::cerr << exception.what() << std::endl;
}

system("PAUSE");
return EXIT_SUCCESS;
}
std::fstream file("sample.in.txt", std::fstream::in);
std::stringstream stream;
stream << file.rdbuf();
file.close();

std::string input = stream.str();

std::regex pattern("answer=\"(.*?)\"");

std::sregex_token_iterator next(std::begin(input), std::end(input), pattern, 1);
std::sregex_token_iterator end;

while (next != end)
{
std::cout << *next++ << std::endl;
}
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2720 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 10ms · UTC 08:48 · PVG 16:48 · LAX 00:48 · JFK 03:48
Developed with CodeLauncher
♥ Do have faith in what you're doing.