C++ 读取文件并存储在不同的数组中

C++ 读取文件并存储在不同的数组中,c++,C++,我需要从文件中读取代码并存储在不同的数组中 例如: 保罗2354 约翰32 56 我的要求如下:我需要在字符串数组中存储paul,john,在一个整数数组中存储23,32;在另一个int数组中,类似地54,56 我从文件中读取输入并打印,但无法保存在3个不同的数组中 int main() { string name; int score; ifstream inFile ; inFile.open("try.txt"); w

我需要从文件中读取代码并存储在不同的数组中

例如:

保罗2354

约翰32 56

我的要求如下:我需要在字符串数组中存储
paul,john
,在一个整数数组中存储
23,32
;在另一个
int
数组中,类似地
54,56

我从文件中读取输入并打印,但无法保存在3个不同的数组中

int main()
{
    string name;
    int score;
    ifstream inFile ;
     
    inFile.open("try.txt");
    while(getline(inFile,name))
    {
        cout<<name<<endl;
    }
    inFile.close();     
    
}
intmain()
{
字符串名;
智力得分;
河流充填;
infle.open(“try.txt”);
while(getline(填充,名称))
{

CUT< P>我假设你是新的编程人员?还是新的C++?所以我提供了示例代码来启动。
#包括;
#包括
#包括
使用名称空间std;
int main(){
载体名称;
向量veca,vecb;
字符串n;
INTA,b;
ifstream fin(“try.txt”);
而(fin>>n>>a>>b){
名称。推回(n);
veca.向后推(a);
向量b.推回(b);

cout您可以尝试以下代码:

#include <string>
#include <vector>

#include <iostream>
#include <fstream>

int main()
{
    std::string fileToRead = "file.log";
    std::vector<int> column2, column3;
    std::vector<std::string> names;
    int number1, number2;
    std::string strName;

    std::fstream fileStream(fileToRead, std::ios::in);
    while (fileStream>> strName >> number1 >> number2)
    {
       names.push_back(strName);
       column2.push_back(number1);
       column3.push_back(number2);
       std::cout << "Value1=" << strName
           << "; Value2=" << number1
           << "; value2=" << number2
           << std::endl;
    }
    fileStream.close();
    return 0;
}

缺少数据结构,例如;Array、Arraylist、Linkedlist和Vectors。您需要该数据结构来保存输入数据并进行存储。
#include <string>
#include <vector>

#include <iostream>
#include <fstream>

int main()
{
    std::string fileToRead = "file.log";
    std::vector<int> column2, column3;
    std::vector<std::string> names;
    int number1, number2;
    std::string strName;

    std::fstream fileStream(fileToRead, std::ios::in);
    while (fileStream>> strName >> number1 >> number2)
    {
       names.push_back(strName);
       column2.push_back(number1);
       column3.push_back(number2);
       std::cout << "Value1=" << strName
           << "; Value2=" << number1
           << "; value2=" << number2
           << std::endl;
    }
    fileStream.close();
    return 0;
}
Value1=paul; Value2=23; value2=54
Value1=john; Value2=32; value2=56