-1
我試圖用GET線從.txt
文件格式讀取整數的「郵政編碼列整數列讀取:從文本文件C++
Name|Address|Zipcode|DateOfBirth
這是有關什麼我到目前爲止部分:
std::ifstream testfile;
testfile.open("data.txt");
string zipcode;
std::vector<int> inputVec;
while(!testfile.eof())
{
std::getline(testfile, zipcode, '|');
// Need to store all zipcodes as ints in an array or vector
// inputVec.push_back(zipcode);
// trying to cout to screen to make sure its the right col.
cout<<zipcode<<endl; // not working
}
然而,這是整個文件讀時,我只想郵政編碼列
我如何Ø nly「搶」'|'
符號之間的那一列?
閱讀所有列,忽視這些你並不需要。除非你的列的寬度是固定的(允許你跳過'n'字節),否則沒有更有效的方法。而且,老實說,無論如何,這並不重要。 – DevSolar
請不要認爲郵政編碼總是整數。在英國,他們就像「CB4 3PT」。鑑於你不能用zip-code進行算術運算,只要將它們作爲字符串處理。 –
一個郵政編碼不應該是一個整數,它應該是一個字符串。郵政編碼可以以「0」開頭,整數不能。 – NathanOliver