我在使用find_last_of时遇到问题
I have problems with using find_last_of
当我试图在文件中找到最后一次出现的"EndProject"时,它看起来像这样:(这是原始VS解决方案文件,没有任何更改):
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASO", "ASOASO.vcxproj", "{574117CD-377D-4C5A-8B6C-B0EAFF8CE158}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "asdfasdf", "asdfasdfasdfasdf.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个字符。肯定有什么不对劲,但怎么了?
std::string::find_last_of()
将查找搜索字符串中任何字符的最后一个出现,而不是整个搜索字符串的最后一次出现:在这种情况下,如果在EndGlobal
中找到o
。
改为使用std::string::rfind()
:
auto end_of_project_manifest = project_file_contents.rfind("EndProject");
相关文章:
- 编译包含字符串的代码时遇到问题
- Usages of std::move
- 遇到新行时,有没有办法停止istream_iterator
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 在 for 循环中查找问题时遇到困难
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 具有变量Number of Arguments的std::函数的矢量
- Capacity of a deque
- 创建结构的数组时遇到分段错误
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 为什么我遇到分段错误?
- Deprecation of _writeBarrier()
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- constexpr begin of a std::array
- 如何调整 std::vector of Eigen::MatrixXd 的大小
- 这些是什么样的错误?即使我不在 Linux 上工作,我也遇到了 Linux 错误
- C++ "error: invalid use of void expression"
- C++14 遇到奇怪的"use of deleted function"错误