如何将文件内容读取到特定类型的变量中?

2026-05-08 15:492阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计195个文字,预计阅读时间需要1分钟。

如何将文件内容读取到特定类型的变量中?

请提供您需要改写的伪原创开头内容,我会帮您进行改写。

如下所示:

#include <iostream> #include <fstream> #include <sstream> #include <string> using namespace std; int main(){ cout << "input the file name: "; string file_name; cin >> file_name; cout << endl; // ifstream infile("1.txt"); ifstream infile(file_name.c_str()); string line; while (std::getline(infile, line)){ std::istringstream iss(line); int a, b; if (!(iss >> a >> b)) { break; } // error cout << "a : " << a << endl; cout << "b : " << b << endl; } return 1; }

以上这篇C++ 读取文件内容到指定类型的变量方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持自由互联。

阅读全文
标签:变量

本文共计195个文字,预计阅读时间需要1分钟。

如何将文件内容读取到特定类型的变量中?

请提供您需要改写的伪原创开头内容,我会帮您进行改写。

如下所示:

#include <iostream> #include <fstream> #include <sstream> #include <string> using namespace std; int main(){ cout << "input the file name: "; string file_name; cin >> file_name; cout << endl; // ifstream infile("1.txt"); ifstream infile(file_name.c_str()); string line; while (std::getline(infile, line)){ std::istringstream iss(line); int a, b; if (!(iss >> a >> b)) { break; } // error cout << "a : " << a << endl; cout << "b : " << b << endl; } return 1; }

以上这篇C++ 读取文件内容到指定类型的变量方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持自由互联。

阅读全文
标签:变量