I have a file with the format below. I want to read the file in and print it out. But when I do read in and print, it will be some garbage. I think it is because the # symbol starts at the line. So, what is the right way to read in the whole file while ignoring the "#" line
int main(){ ifstream inFile; inFile.open("city_list.txt"); string name; int zone; int rank; static std::string const symbols = "#"; while (true){ inFile >> zone >> name >> rank; cout << zone << " " << name<< " " << rank << endl } } Input File (city_list.txt)
# AFRICA Zone 1 1 Cairo_EG 30 1 Johannesburg_SA -26 1 Lagos_NG 6 # ASIA Zone 2 2 Beijing_CN 3 #2 Hong_Kong_CN 2 https://stackoverflow.com/questions/66631781/ignore-the-symbol-when-reading-the-file-c March 15, 2021 at 10:51AM
没有评论:
发表评论