这是我创建的文本文件
产品名称、价格、供货情况。
油,20 美元,是
油漆,25 美元,是
汽车蜡,35 美元,没有
制动液,50 美元,是
我想逐行从文件中读取这些数据,然后将其拆分为逗号(,)符号并将其保存在字符串数组中。
string findProduct(string nameOfProduct)
{
string STRING;
ifstream infile;
string jobcharge[10];
infile.open ("partsaval.txt"); //open the file
int x = 0;
while(!infile.eof()) // To get you all the lines.
{
getline(infile,STRING); // Saves the line in STRING.
stringstream ss(STRING);
std::string token;
while(std::getline(ss, token, ','))
{
//std::cout << token << '\n';
}
}
infile.close(); // closing the file for safe handeling if another process wantst to use this file it is avaliable
for(int a= 0 ; a < 10 ; a+=3 )
{
cout << jobcharge[a] << endl;
}
}
问题:
当我删除打印令牌行上的注释时,所有数据都被完美打印,但是当我尝试打印数组的内容(jobcharge [])时,它什么也不打印。