当我尝试在文件中查找"EndProject“的最后一次出现时,它看起来像这样:(这是原始的VS解决方案文件,没有任何更改):
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASO", "ASO\ASO.vcxproj", "{574117CD-377D-4C5A-8B6C-B0EAFF8CE158}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asdfasdf", "asdfasdf\asdfasdf.vcxproj", "{05527F0D-4B98-4A55-B038-3C60005566CB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{574117CD-377D-4C5A-8B6C-B0EAFF8CE158}.Debug|Win32.ActiveCfg = Debug|Win32
{574117CD-377D-4C5A-8B6C-B0EAFF8CE158}.Debug|Win32.Build.0 = Debug|Win32
{574117CD-377D-4C5A-8B6C-B0EAFF8CE158}.Release|Win32.ActiveCfg = Release|Win32
{574117CD-377D-4C5A-8B6C-B0EAFF8CE158}.Release|Win32.Build.0 = Release|Win32
{05527F0D-4B98-4A55-B038-3C60005566CB}.Debug|Win32.ActiveCfg = Debug|Win32
{05527F0D-4B98-4A55-B038-3C60005566CB}.Debug|Win32.Build.0 = Debug|Win32
{05527F0D-4B98-4A55-B038-3C60005566CB}.Release|Win32.ActiveCfg = Release|Win32
{05527F0D-4B98-4A55-B038-3C60005566CB}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal我使用的是:
auto end_of_project_manifest = project_file_contents.find_last_of("EndProject");//here project_file_contents is a string filed with contents of this file.我得到的结果是1308,这很奇怪,因为这个文件总共只有1313个字符。肯定有什么问题,但是是什么呢?
发布于 2012-02-24 21:13:19
std::string::find_last_of()将查找搜索字符串中任何字符的最后一个匹配项,而不是整个搜索字符串的最后一个匹配项:在本例中,if查找EndGlobal中的o。
请改用std::string::rfind():
auto end_of_project_manifest = project_file_contents.rfind("EndProject");https://stackoverflow.com/questions/9431281
复制相似问题