\n,\r与endl的区别,该怎么解决

\n,\r与endl的区别
本人是一大二学生,并不是纯的计算机专业的,计算机科目只是其中一部分,所以水平有限,请大家见谅,我今天尝试文件流遇到一个疑惑。这是我的测试代码,在Visual studio 2008下的。
#include "stdafx.h"
#include <iostream>
using namespace std;

#include<fstream>
#include<string>
int main()
{
  string i;
ifstream fin("test.txt");
ofstream fout("test.txt");
fout<<"123456"<<endl;
getline(fin,i);
cout<<i;
system("pause");
}
发现把其中的endl改为放在里面的\n,\r或者不加都不能正常读入,这是为什么呢?听说endl有什么清空缓冲区,不理解和我的程序有什么意义。

------解决方案--------------------
用了endl后才把123456字符串写到文件中,下面的getline才从文件中正确地读出;
而用了'\n'之类的,没把123456字符串写到文件中,getline从文件中什么也没读到