C ++:我可以使用.find函数在字符串中查找多个元素

时间:2018-06-22 21:23:50

标签: c++ arrays string character linear-equation

c ++:我可以使用.find函数在字符串中查找多个字符吗? 例如:在线性方程组中寻找+和-

1 个答案:

答案 0 :(得分:1)

一种实现方式:

<!DOCTYPE html>
<!--[if IE 9 ]><html class="ie ie9" lang="en" class="no-js"> <![endif]-->
<!--[if !(IE)]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="description" content="INS 24/7" />
    <meta name="keywords" content="" />
    <meta name="author" content="DMR" />

    <title>Red Medica</title>


    <link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="~/Content/font-awesome.css" rel="stylesheet" type="text/css">
    <link href="~/Content/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css">
    <link href="~/Style/css/main.css" rel="stylesheet" type="text/css">
    <link href="~/Style/css/skins/INS247.css" rel="stylesheet" type="text/css">
    <link href="~/Style/css/my-custom-styles.css" rel="stylesheet" type="text/css">


    @Styles.Render("~/bundles/theme")
    @Styles.Render("~/Content/bebasneue")


    <!--JavaScript-->
</head>
<body class="sidebar-fixed topnav-fixed dashboard">

    <!-- WRAPPER -->
    <div id="wrapper" class="wrapper">

        <!-- TOP BAR -->
        <div class="top-bar navbar-fixed-top">
            <div class="container">
                <div class="clearfix">
                    <a href="#" class="pull-left toggle-sidebar-collapse"><i class="fa fa-bars"></i></a>
                    <!-- logo -->
                    <div class="pull-left left logo">
                        @*<img src="~/Content/img/Logo.png" alt="" />*@

                    </div>
                    <!-- end logo -->
                </div>
            </div>
            <!-- /container -->
        </div>
        <!-- END TOP BAR -->
        <!-- LEFT SIDEBAR -->
        <div>
            <br />
        </div>
        <div id="left-sidebar" class="left-sidebar" style="background-color:#222d32">
            <!-- main-nav -->
            <div class="sidebar-scroll">
                <nav class="main-nav">
                    <ul class="main-menu">
                        <li >
                            <a href="/Home/Index">
                                <i class="fa fa-home">
                                </i><span class="text">Inicio</span>
                            </a>
                        </li>
                        <li>
                            <a href="#" class="js-sub-menu-toggle">
                                <i class="fa fa-picture-o"></i><span class="text">Imagen</span>
                                <i class="toggle-icon fa fa-angle-down"></i>
                            </a>
                            <ul class="sub-menu">
                                <li>
                                    <a href="/Imagen/CargarImagen">
                                        <i class="fa fa-cloud-upload">
                                        </i><span class="text">Cargar Imagen</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="/Imagen/ActualizarImagen">
                                        <i class="fa fa-refresh">
                                        </i><span class="text">Actualizar Imagen</span>
                                    </a>
                                </li>
                                <li>
                                    <a href="/Imagen/BorrarImagen">
                                        <i class="fa fa-trash-o">
                                        </i><span class="text">Borrar Imagen</span>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </nav>
                <!-- /main-nav -->
            </div>
        </div>
        <!-- END LEFT SIDEBAR -->
        <!-- MAIN CONTENT WRAPPER -->
        <div id="main-content-wrapper" class="content-wrapper ">

            @RenderBody()
        </div>
        <!-- END CONTENT WRAPPER -->
    </div>
    <!-- END WRAPPER -->
    <!-- Javascript -->
    <script src="~/js/jquery/jquery-2.1.0.js"></script>


    <script src="~/js/bootstrap/bootstrap.js"></script>
    <script src="~/js/plugins/modernizr/modernizr.js"></script>
    <script src="~/js/plugins/bootstrap-tour/bootstrap-tour.custom.js"></script>
    <script src="~/js/plugins/jquery-slimscroll/jquery.slimscroll.min.js"></script>
    <script src="~/js/king-common.js"></script>
    <script src="~/js/plugins/stat/jquery.easypiechart.min.js"></script>
    <script src="~/js/plugins/raphael/raphael-2.1.0.min.js"></script>
    <script src="~/js/plugins/stat/flot/jquery.flot.min.js"></script>
    <script src="~/js/plugins/stat/flot/jquery.flot.resize.min.js"></script>
    <script src="~/js/plugins/stat/flot/jquery.flot.time.min.js"></script>
    <script src="~/js/plugins/stat/flot/jquery.flot.pie.min.js"></script>
    <script src="~/js/plugins/stat/flot/jquery.flot.tooltip.min.js"></script>
    <script src="~/js/plugins/jquery-sparkline/jquery.sparkline.min.js"></script>
    <script src="~/js/plugins/datatable/jquery.dataTables.min.js"></script>
    <script src="~/js/plugins/datatable/dataTables.bootstrap.js"></script>
    <script src="~/js/plugins/jquery-mapael/jquery.mapael.js"></script>
    <script src="~/js/plugins/raphael/maps/usa_states.js"></script>
    <script src="~/js/king-chart-stat.js"></script>
    <script src="~/js/king-table.js"></script>
    <script src="~/js/king-components.js"></script>
    <script src="~/Scripts/Imagen/AgregarImagen.js"></script>
    <script src="~/Scripts/load-image.all.min.js"></script>

    @RenderSection("scripts", required: false)


</body>

</html>

https://en.cppreference.com/w/cpp/algorithm/find

您还可以使用std :: strpbrk,它在字符串中搜索一个或多个分隔符。 https://en.cppreference.com/w/cpp/string/byte/strpbrk

根据您要对字符串进行标记化的注释,std :: strtok将完成此工作:

auto it = std::find_if( str.begin(), str.end(), [](char c){
    return c == '+' || c == '-';
} );

https://en.cppreference.com/w/cpp/string/byte/strtok

警告:上面的代码不是线程安全的。