Hi mọi người,
Em có viết 1 đoạn code nhỏ tính tổng 2 phân số nhập từ file INPUT và xuất kết quả xuất ra file OUTPUT
INPUT.txt
1/2
3/4
OUTPUT.txt
5/4
Source code:
#include <iostream>
#include <fstream>
int UCLN(int a, int b) // dùng thuật toán Euclid
{
if (a % b == 0)
return b;
return UCLN(b, a % b);
}
int main()
{
std::ifstream FileIn;
FileIn.open("INPUT.txt", std::ios_base::in);
int numerator1, demonstrator1, numerator2, demonstrator2;
FileIn >> numerator1;
FileIn.seekg(1, SEEK_CUR); // bỏ qua dấu "/"
FileIn >> demonstrator1 >> numerator2;
FileIn.seekg(1, SEEK_CUR);
FileIn >> demonstrator2;
FileIn.close();
int result_numerator, result_demonstrator;
result_numerator = numerator1 * demonstrator2 + demonstrator1 * numerator2;
result_demonstrator = demonstrator1 * demonstrator2;
int _UCLN = UCLN(result_numerator, result_demonstrator);
result_numerator /= _UCLN;
result_demonstrator /= _UCLN;
std::ofstream FileOut;
FileOut.open("OUTPUT.txt", std::ios_base::out);
FileOut << result_numerator<< "/" << result_demonstrator;
FileOut.close();
return 0;
}
Nhưng khi build & run Codeblocks báo lỗi như đã đề cập trên title topic, cụ thể là ở dòng FileIn.seekg(1, SEEK_CUR);.
Mọi người ai biết lỗi này giúp mình nhé, xin cảm ơn 
P/S: Đoạn code trên chạy bình thường trên Microsoft Visual Studio 2015, nhưng không hiểu sao CodeBlocks báo lỗi như vậy !


83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?