首页 > 其他分享 >Get file content as string

Get file content as string

时间:2022-12-18 23:33:54浏览次数:32  
标签:std string stream Get content file

bool GetContent(const std::string &file_name, std::string *content) {
  std::ifstream fin(file_name);
  if (!fin) {
    return false;
  }

  std::stringstream str_stream;
  str_stream << fin.rdbuf();
  *content = str_stream.str();
  return true;
}

标签:std,string,stream,Get,content,file
From: https://www.cnblogs.com/sunwenqi/p/16991267.html

相关文章

  • cppconn cpp create table in cpp file ,show current date time in mysql cli via s
    //Model/mysqlhelper.h#ifndef__mysqlhelper_h__#define__mysqlhelper_h__#include<chrono>#include<ctime>#include<fstream>#include<iomanip>#include<i......
  • Python中String模块
    目录Python中String模块详解一、字符串常量二、类1、格式化1.1介绍1.2简单应用1.3格式化输出2、模板化三、函数Python中String模块详解一、字符串常量String库......
  • msprofiler 性能调优命令行实战(口罩识别推理)
    案例介绍本案例使用口罩识别推理程序作为例子进行演示,硬件平台是华为昇腾310设备(Ascend310),该口罩识别使用目标检测中SSD模型,检测的结果有两个类别:戴口罩的脸、没带口罩的......
  • DockerCompose编排Nginx时提示/etc/nginx/mime.types" failed (2: No such file or di
    场景使用DockerCompose编排项目时,其中nginx的服务的yml为nginx:image:nginx:latestports:-"390:390"volumes:-./nginx/font/dist:/u......
  • File类
    一File类概述1File在java.io包下(只有lang包下的不用导包)2主要用于文件和目录(文件夹)的创建、查找和删除等操作3File类的对象是文件和目录路径名的抽象表示形式(即File......
  • [编程基础] Python格式化字符串常量f-string总结
    Python格式化字符串常量f-string总结本文主要总结在Python中如何使用格式化字符串常量f-string(Formattedstringliterals)。在Python程序中,大部分时间都是使用%s或fo......
  • f-strings: Python字符串处理的瑞士军刀
    从3.6开始,Python新增了一个格式化字符串的方法,称之为f-string。其用法就是在python原始字符串的基础上增加f/F前缀,以大括号{}标明被替换的字段。f-string在本质......
  • redis常用命令之string&list
    redis常用操做stringkey操作string<key:value>setnamejohngetnamelistsetnx<keyvalue>setnxgendermale(分布式锁)getgendersetnxgoods_1111delgoods_1ge......
  • Dockfile 参考
    FROMubuntu:16.04WORKDIR/usr/local/binCOPY./res/usr/local/resCOPY./bin/usr/local/binCOPY./baumer/Ubuntu-16.04/arm64/usr/local/bin/ctiENVhttp_proxy"htt......
  • StringJoiner类
    StringJoiner类是jdk8新增的一个类,但是目前被用到的不多。其底层使用的依然是StringBuilder看下面一个例子可以看出同样是拼接出[1,2,3]StringJoiner比StringBuilder渐......