分享

cin.cpp

 望穿墙 2013-12-08
/*
 * cin.cpp
 *
 *  Created on: 2013-10-1
 *      Author: Administrator
 */
#include<iostream.h>

/*
 * getline() 会自动丢弃delimiter
 * 而不是将其留在istream流中作为下一个输入的字符
 * get()会留在istream流中
 */
#if 0
int main(void)
{
    int a;
    int x,y,z;
    cout << "cin对象和提取操作符应用举例!\n";
    cout << "请输入一个整数: ";
    cin >> a;
    cout << "您输入的整数是: " << a << endl;
    cout << "请连续输入三个整数: ";

    cin >> x >> y >> z;
    cout << "您输入的三个整数是: " << x << ","
    << y << "," << z <<endl;
    return 0;
}
#endif

#if 0
int main(void)
{
    char c0;
    cout << "get函数\n";
    cout << "input a char\n";
    c0 = cin.get();
    cout << c0 << endl;
    cout << "input three char\n";
    char c1,c2,c3;
    cin.get(c0);
    cin.get(c1).get(c2).get(c3);
    cout << c1 << "," << c2 << "," << c3 << endl;
    char *str = new char;
    cout << "input one hundred char , X to exit\n";
    cin.get(str,100,'X');
    cout << str << endl;
    return 0;
}
#endif
#if 0
int main(void)
{
    cout << "getline function!\n";
    char *str = new char;
    cout << "please input one line char\n";
    cin.getline(str,1000,'\n');
    cout << str << endl;
    return 0;
}
#endif
#if 0
int main(void)
{
    cout << "read function!\n";
//    char mm[9];
//    char *ch = mm;
    char *mm = new char;
    cout << "please input eight char\n";
    cin.read(mm,8);
    mm[8] = '\0';
    cout << mm << endl;
    return 0;
}
#endif

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多