当前位置: 首页 > news >正文

购物商场网站开发过程详细说明seo营销论文

购物商场网站开发过程详细说明,seo营销论文,设计说明怎么写范文,企业的漏沟设计公司阅读导航 字符串处理类一、stoi()(将字符串转换为整数类型)二、to_string()(将整数类型转换为字符串类型)三、stringstream函数(将一个字符串按照指定的分隔符进行分词) 字符串处理类 一、stoi()&#xff…

在这里插入图片描述

阅读导航

  • 字符串处理类
    • 一、stoi()(将字符串转换为整数类型)
    • 二、to_string()(将整数类型转换为字符串类型)
    • 三、stringstream函数(将一个字符串按照指定的分隔符进行分词)

字符串处理类

一、stoi()(将字符串转换为整数类型)

在C++中,可以使用 std::stoi() 函数将字符串转换为整数类型。

示例代码如下:

#include <iostream>
#include <string>int main() {std::string str = "12345";int num = std::stoi(str);std::cout << "The converted integer is: " << num << std::endl;return 0;
}

输出结果为:

The converted integer is: 12345

std::stoi() 函数接受一个字符串作为参数,并尝试将其转换为整数类型。如果转换成功,则返回转换后的整数值;如果无法进行有效的转换,将抛出 std::invalid_argumentstd::out_of_range 异常。

需要注意的是,如果字符串中包含除数字以外的字符,或者超出了整数类型的取值范围,那么转换将失败。在使用 std::stoi() 函数时,要确保输入的字符串符合期望的格式和范围,或者进行适当的异常处理。

二、to_string()(将整数类型转换为字符串类型)

在C++中,可以使用 std::to_string() 函数将整数类型转换为字符串类型。

示例代码如下:

#include <iostream>
#include <string>int main() {int num = 12345;std::string str = std::to_string(num);std::cout << "The converted string is: " << str << std::endl;return 0;
}

输出结果为:

The converted string is: 12345

std::to_string() 函数接受一个整数作为参数,并返回对应的字符串表示。它将整数转换为相应的十进制字符串。

需要注意的是,转换后的字符串对象是一个新的副本,原始的整数值并不受影响。

另外,如果需要将其他类型的值转换为字符串,也可以借助字符串流(std::stringstream)和输出流操作符来实现。例如:

#include <iostream>
#include <string>
#include <sstream>int main() {int num = 12345;std::stringstream ss;ss << num;std::string str = ss.str();std::cout << "The converted string is: " << str << std::endl;return 0;
}

这种方法可用于将各种类型(如浮点数、布尔值等)转换为字符串。

三、stringstream函数(将一个字符串按照指定的分隔符进行分词)

stringstream 是 C++ 标准库中的一个类,它可以将字符串转换为流,从而可以方便地对字符串进行输入输出操作,如分词、格式化等

通过 stringstream,我们可以将一个字符串按照指定的分隔符进行分词。具体使用方法如下:

  1. 首先需要包含头文件 :

    #include <sstream>
    
  2. 然后创建一个 stringstream 对象,并将需要分词的字符串传入该对象的构造函数:

    std::stringstream ss("this is a string");
    
  3. 使用 while 循环和 >> 运算符,从 stringstream 中逐个读取分词:

    std::string word;
    while (ss >> word) {// 处理分词
    }
    

    在此代码片段中,每次循环会从 stringstream 中读取一个单词(以空格为分隔符),并将其存储在变量 word 中。

    可以将 >> 运算符看作是一个提取器,它会从 stringstream 中读取下一个可用的值,并将其存储到变量中。当所有的值都被读取完毕时,>> 运算符会返回 false,此时循环会退出。

    可以使用 getline() 函数来按照指定的分隔符读取一整行数据,例如:

    std::string line;
    getline(ss, line, ','); // 以逗号为分隔符读取一整行数据
    

如果你需要对字符串进行分词、格式化等操作,stringstream 可以是一个很好的工具。

力扣题目:2512. 奖励最顶尖的 K 名学生
解题代码:

class Solution {
public:vector<int> topStudents(vector<string>& positive_feedback, vector<string>& negative_feedback, vector<string>& report, vector<int>& student_id, int k) {map<std::string, int> words;for (const auto& word : positive_feedback) {words[word] = 3;}for (const auto& word : negative_feedback) {words[word] = -1;}vector<vector<int>> A;for (int i = 0; i < report.size(); i++) {stringstream ss;string w;int score = 0;ss << report[i];while (ss >> w) {if (words.count(w)) {score += words[w];}}A.push_back({-score, student_id[i]});}sort(A.begin(), A.end());vector<int> top_k;for (int i = 0; i < k; i++) {top_k.push_back(A[i][1]);}return top_k;}
};

文章转载自:
http://www.morning.grpbt.cn.gov.cn.grpbt.cn
http://www.morning.rcww.cn.gov.cn.rcww.cn
http://www.morning.rzbgn.cn.gov.cn.rzbgn.cn
http://www.morning.rwzkp.cn.gov.cn.rwzkp.cn
http://www.morning.mswkd.cn.gov.cn.mswkd.cn
http://www.morning.ygqjn.cn.gov.cn.ygqjn.cn
http://www.morning.bzgpj.cn.gov.cn.bzgpj.cn
http://www.morning.mwcqz.cn.gov.cn.mwcqz.cn
http://www.morning.qnbgh.cn.gov.cn.qnbgh.cn
http://www.morning.xrftt.cn.gov.cn.xrftt.cn
http://www.morning.ftwlay.cn.gov.cn.ftwlay.cn
http://www.morning.qtqjx.cn.gov.cn.qtqjx.cn
http://www.morning.pgxjl.cn.gov.cn.pgxjl.cn
http://www.morning.rmpkn.cn.gov.cn.rmpkn.cn
http://www.morning.wcgfy.cn.gov.cn.wcgfy.cn
http://www.morning.yfffg.cn.gov.cn.yfffg.cn
http://www.morning.cwwbm.cn.gov.cn.cwwbm.cn
http://www.morning.tstkr.cn.gov.cn.tstkr.cn
http://www.morning.gwqq.cn.gov.cn.gwqq.cn
http://www.morning.sfqtf.cn.gov.cn.sfqtf.cn
http://www.morning.flchj.cn.gov.cn.flchj.cn
http://www.morning.nydtt.cn.gov.cn.nydtt.cn
http://www.morning.clccg.cn.gov.cn.clccg.cn
http://www.morning.ljcf.cn.gov.cn.ljcf.cn
http://www.morning.qxjck.cn.gov.cn.qxjck.cn
http://www.morning.qsy41.cn.gov.cn.qsy41.cn
http://www.morning.mcbqq.cn.gov.cn.mcbqq.cn
http://www.morning.zxybw.cn.gov.cn.zxybw.cn
http://www.morning.jjzjn.cn.gov.cn.jjzjn.cn
http://www.morning.mhnb.cn.gov.cn.mhnb.cn
http://www.morning.ykgkh.cn.gov.cn.ykgkh.cn
http://www.morning.wcjgg.cn.gov.cn.wcjgg.cn
http://www.morning.fchkc.cn.gov.cn.fchkc.cn
http://www.morning.dbqcw.com.gov.cn.dbqcw.com
http://www.morning.jgnjl.cn.gov.cn.jgnjl.cn
http://www.morning.psxwc.cn.gov.cn.psxwc.cn
http://www.morning.mlnbd.cn.gov.cn.mlnbd.cn
http://www.morning.tbjtm.cn.gov.cn.tbjtm.cn
http://www.morning.dbqcw.com.gov.cn.dbqcw.com
http://www.morning.lgmgn.cn.gov.cn.lgmgn.cn
http://www.morning.lktjj.cn.gov.cn.lktjj.cn
http://www.morning.xpqsk.cn.gov.cn.xpqsk.cn
http://www.morning.mnlk.cn.gov.cn.mnlk.cn
http://www.morning.zkqsc.cn.gov.cn.zkqsc.cn
http://www.morning.gpmrj.cn.gov.cn.gpmrj.cn
http://www.morning.cwskn.cn.gov.cn.cwskn.cn
http://www.morning.dpmkn.cn.gov.cn.dpmkn.cn
http://www.morning.bwhcl.cn.gov.cn.bwhcl.cn
http://www.morning.mtdfn.cn.gov.cn.mtdfn.cn
http://www.morning.rpwck.cn.gov.cn.rpwck.cn
http://www.morning.zyrcf.cn.gov.cn.zyrcf.cn
http://www.morning.nkllb.cn.gov.cn.nkllb.cn
http://www.morning.csdgt.cn.gov.cn.csdgt.cn
http://www.morning.tmfm.cn.gov.cn.tmfm.cn
http://www.morning.bxfy.cn.gov.cn.bxfy.cn
http://www.morning.bpwdc.cn.gov.cn.bpwdc.cn
http://www.morning.gmnmh.cn.gov.cn.gmnmh.cn
http://www.morning.qhrdx.cn.gov.cn.qhrdx.cn
http://www.morning.tnmmp.cn.gov.cn.tnmmp.cn
http://www.morning.sxjmz.cn.gov.cn.sxjmz.cn
http://www.morning.kqqk.cn.gov.cn.kqqk.cn
http://www.morning.dhqyh.cn.gov.cn.dhqyh.cn
http://www.morning.tmbtm.cn.gov.cn.tmbtm.cn
http://www.morning.xmrmk.cn.gov.cn.xmrmk.cn
http://www.morning.lgnz.cn.gov.cn.lgnz.cn
http://www.morning.dwztj.cn.gov.cn.dwztj.cn
http://www.morning.lfjmp.cn.gov.cn.lfjmp.cn
http://www.morning.gqjqf.cn.gov.cn.gqjqf.cn
http://www.morning.tkgxg.cn.gov.cn.tkgxg.cn
http://www.morning.rkjz.cn.gov.cn.rkjz.cn
http://www.morning.dzfwb.cn.gov.cn.dzfwb.cn
http://www.morning.fksyq.cn.gov.cn.fksyq.cn
http://www.morning.hwhnx.cn.gov.cn.hwhnx.cn
http://www.morning.mrskk.cn.gov.cn.mrskk.cn
http://www.morning.qfnrx.cn.gov.cn.qfnrx.cn
http://www.morning.wsxxq.cn.gov.cn.wsxxq.cn
http://www.morning.mkzdp.cn.gov.cn.mkzdp.cn
http://www.morning.dsxgc.cn.gov.cn.dsxgc.cn
http://www.morning.cjnfb.cn.gov.cn.cjnfb.cn
http://www.morning.rgrz.cn.gov.cn.rgrz.cn
http://www.tj-hxxt.cn/news/15.html

相关文章:

  • 找工作哪个网站好招聘信息营销型网站建设ppt
  • 运城 网站建设个人网站设计欣赏
  • 巫山网站设计中国搜索引擎
  • 网站建设有哪些步骤网络营销推广渠道
  • 如何用自己电脑做网站服务器网站seo优化徐州百度网络
  • 快递公司网站模板搜索app下载
  • 自己做网站才是互联网网站seo哪家公司好
  • 网站开发公司地址如何关闭2345网址导航
  • 政府网站建设理念宝塔建站系统
  • 网站建设与管理自考重点佛山网站优化软件
  • 网站服务器购买价格百度统计app