Hello Mat

 找回密码
 立即注册
查看: 2174|回复: 0

C++读取txt

[复制链接]

1298

主题

1524

帖子

114

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22653
发表于 2022-3-16 21:40:26 | 显示全部楼层 |阅读模式
读取txt
  1. #include<fstream>
  2. #include<string>
  3. #include<iostream>
  4. using namespace std;
  5. void main()
  6. {undefined
  7. ifstream in("main.txt");
  8. string s;
  9. while(getline(in,s))//着行读取数据并存于s中,直至数据全部读取
  10. cout<<s.c_str()<<endl;
  11. }
复制代码
  1. string get_KeyStr(const char* filename)
  2. {
  3.         std::string str = "";
  4.         std::string temp[3000];
  5.         string infile(filename);
  6.         ifstream fin;
  7.         fin.open(infile, ios::in);
  8.         int i = 0;
  9.         while (fin.good() && i < 3000)
  10.         {
  11.                 getline(fin, temp[i]);
  12.                 str += temp[i]; // += 已被重载
  13.                 i++;
  14.         }
  15.         fin.close();
  16.         return str;
  17. }
复制代码



参考“
【1】https://blog.csdn.net/qing101hua/article/details/51925204/



算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-5-20 09:15 , Processed in 0.220043 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表