C++ 별도의 배열의 각 값을 저장 : 같은 파일로 다시 저장 한 후,이를 편집,는 텍스트 파일에서 읽고 나는 다음과 같은 내용을 읽을하려고
rima doha 44881304 20 30 10 10 20 10102 10102
andrew ny 123456 12 12 13 14 15 01020 03040
별도의 배열에 저장합니다.
ifstream infile;
infile.open("D:\\customers.txt");
string names[100];
string addresses[100];
int tn[100];
int numCalls[100];
int trunkCalls[100];
int numMobCalls[100];
int isdnNum[100];
int dueD[100];
int paymentD[100];
int numOfPpl = 0;
int numOfPpl = 0;
for(int i=0; i<100; i++){
infile >> names[i] >> addresses[i]>>tn[i]>>numCalls[i]>>trunkCalls[i]>> numMobCalls[i]>> isdnNum[i]>>dueD[i]>>paymentD[i];
numOfPpl++;
}
//Code where some values were edited
ofstream outfile("D:\\customers.txt");
for(int i=0; i<numOfPpl; i++)
{
outfile<<names[i] << "\t" <<addresses[i] << "\t" <<tn[i]<<"\t" <<numCalls[i]<<"\t"
<<trunkCalls[i]<<"\t"<<numMobCalls[i]<<"\t"<<numMobCalls[i]<<"\t"<<isdnNum[i]<<"\t"<<dueD[i]<<"\t"<<paymentD[i]<<endl;
}
outfile.close();
infile.close();
문제는 처음 두 줄이 제대로 저장되지만, 다음 파일에 임의의 값이 있다는 것입니다 :
여기 내 시도 코드입니다. 이 문제를 어떻게 해결할 수 있습니까?
파일에 몇 줄이 있습니까? – P0W
당신은 아마 쓰레기 값을 얻고 있습니다, 그것들은 큰 음수입니까? 나는 당신이 i -> 100을 루핑하기 때문에 문제가 있다고 가정 할 것이다. 그래서 파일에 100 줄이 없다면 빈 줄이 쓰레기 값이 될 것이다. –
다른 하나는 사용하지 마십시오. StackOverflow에서 "C++ read file columns"를 검색 했습니까? –