Example :
- Đọc vào file như bình thường, kiểm tra xem nó là chữ hay số dùng isalpha.
- Nếu chữ thì skip nó.
- Dùng istringstream chuyển lại thành số sau đó muốn tình gì thì tính.
Tui dùng vector để put dữ liệu vào đó, cậu thích dùng mãng hay gì đó thì tùy.
C++ Code:
#include <iostream> #include <fstream> #include <string> #include <sstream> #include <cctype> #include <vector> int main() { std::ifstream client_file("abc.txt"); std::string line; std::vector< int > student_grade; int index; while(std::getline(client_file, line)){ if(isalpha(line[0])){ continue; } else{ int grade; std::istringstream iss(line); iss >> grade; student_grade.push_back(grade); } } for(index = 0; index < student_grade.size(); ++index){ } }