拆分包含分隔符的每个数组元素并保存到C ++中的另一个数组中

时间:2016-11-14 05:06:08

标签: c++ arrays text-files getline stringstream

我的文本文件如下所示:

submitHandler()

我试图将每一行保存到这样的数组中:

my bag;A5;B5;C5;D5;E5
watch;E4;F4;G4;H4
the sofa;F6;G6;H6
handphones;C2;D2;E2
babies;D6;D7

我正在尝试将文本文件的每一行保存到像这样的数组中

string type[100];
string line;
int count = 0;
string item1;

ifstream infile;
infile.open("txtmess.txt");

while (getline(infile, line))          

            {     
           //cout<<line<<endl; //just to check
            type[count] = fline;       
            count++;                  
            stringstream ss(type[count]);                   
            getline(ss, item1, ';'); 
            cout<<type[count]<<endl; //not printing . 
            cout<<item1<<endl;       //not printing .           

            }
infile.close();

然而,当我尝试cout数组时,它会打印一个空白

我想要做的是将每个数组(类型[])拆分为另一个这样的getline并保存到另一个数组中:

type[0] =   my bag;A5;B5;C5;D5;E5
  type[1] =   watch;E4;F4;G4;H4
 type[2] =    the sofa;F6;G6;H6
 type[3] =    handphones;C2;D2;E2
  type[4] =   babies;D6;D7

0 个答案:

没有答案
相关问题