如何在文件中读取不同的数据类型?C
How can i read different data type in a file? C++
这是我项目的代码..现在我想将名称存储在字符串变量中,然后将性别存储在char type变量中等等。此代码将名字存储在Sepreate变量中,姓氏在其他变量中。然后如何存储在不同的变量中?
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
string array[14][10];
ifstream read("file.txt");
if(read.fail())
cerr << "ërrier"<< endl;
for(int i=0;!read.eof();i++)
{
for(int j=0;j<10;j++)
{
read>> array[i][j];
cout<< array[i][j]<<" ";
}
cout<< endl;
}
read.close();
return 0;
}
这是我要读的文件。.帮助我
我不仔细地知道您的目的。但是,如果您的目的是几个字符串变量或其他类型的商店名称和家庭,您可以使用指针:
std::string *name;
std::vector<std::string *> names;
for(int i=0;!read.eof();i++)
{
for(int j=0;j<10;j++)
{
name = new std::string;
read>> *name;
cout<< *name<<" ";
//this line help us to keep pointers, you can access to pointers,
names.pushback(name).
}
cout<< endl;
}
相关文章:
- 读取 C++ 中的 Fortran 数据类型
- Poco c++ 如何从PostgreSQL DB读取"text"数据类型?
- 需要根据读取的数据类型将ifstream提取到单独的数组中
- 创建一个模板函数来读取 hdf5 中的任意数据类型
- 在C 中按行读取文本文件,每行都是不同的数据类型
- 我如何使用GO语言读取可能是两种不同数据类型之一的HDF5属性
- 当拥有倍数数据类型C 时,正确读取文件末尾的方法
- 解析一般CSV读取功能时,如何处理不同的数据类型?(不明确指定它们)
- 如何在文件中读取不同的数据类型?C
- 如何通过读取文件将不同数据类型的数据推送到向量中
- C++ 从文本文件数据类型读取为结构,并将数据存储在列表的向量中
- 数据类型类和读取器/解析器之间的耦合
- c++我需要将文件中的数据读取到多维数组中,然后用一种数据类型对数组进行排序.怎样
- 从.txt文件中读取多个数据类型,其中一个字符串有空格C++
- C++读取具有不同数据类型的列式存储中的 CSV 表
- 从输入文件中读取多种数据类型
- 读取 C++ 行中的不同数据类型
- 正在从包含Int和Char数据类型的文件中读取
- 如何从套接字读取接收自定义数据类型
- 隐藏复合数据类型的某些字段,使其不被写入(或从hdf5文件中读取)