求大神指教,小白感激不尽

#include
#include
using namespace std;
int main()
{
ofstream outf("test.dat");
char p[]="I am a student";
outf<

outf.close();
ifstream inf("test.dat");
inf>>p;
cout<<p<<endl;
return 0;
}
为什么输出结果只有一个I?不应该输出I am a student吗?求大神指教

调试一下 它读取空格读取的是0 相当于字符串的结尾 所以只输出I

 #include<iostream>
#include<stdio.h>
#include <fstream>
using namespace std;

int main()
{
    ofstream outf("test.dat");
    char p[]="I am a student";
    outf<<p;
    outf.close();
    ifstream inf("test.dat");
    inf>>p;
    for(int i=0;i<15;i++)
        cout<<p[i];
    return 0;
}

用gets,支持空格
http://blog.csdn.net/good_luck512233/article/details/52791005

字符串的话用getchar或string然后for循环输入单个字符咯,但是cin不支持空格和回车,要用scanf