400 028 6601

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

istream常用函数有哪些

本篇内容介绍了“istream常用函数有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

10年的静海网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。网络营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整静海建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“静海网站设计”,“静海网站推广”以来,每个客户项目都认真落实执行。

标准库

get

  1. 获取单个字符

int get();
istream& get (char& c);

从输入缓冲区获取单个字符,无参数时返回获取到的字符的asc码,有参数时把获取到的字符存储到参数中。

代码测试:

#include 

using namespace std;

int main () {
    char a, b, c;
    int res = cin.get();
    cout << "res: " << res << endl;
    
    cin.get(a).get(b).get(c);
    cout << "a: " << a << "\nb: " << b << "\nc: " << c << endl;
    return 0;
}
输入:abcdef
输出:
res: 97
a: b
b: c
c: d

2.获取c风格的字符串

istream& get (char* s, streamsize n);
istream& get (char* s, streamsize n, char delim);

代码测试:

#include 
using namespace std;

int main () {
    char ch[1024];
    cin.get(ch, 10);
    cout << "ch2: " << ch << endl;
    cin.get(ch, 10, ',');
    cout << "ch3: " << ch << endl;
    cin.get(ch, 10, ',');
    cout << "ch4: " << ch << endl;
    return 0;
}
输入:
aaabbbcccddd,eeefffhhhiii
输出:
ch2: aaabbbccc
ch3: ddd
ch4:

3.获取streambuf

istream& get (streambuf& sb);
istream& get (streambuf& sb, char delim);
#include 
#include 
using namespace std;

int main () {
    stringbuf sb;
    cin.get(sb, ',');
    cout << sb.str();
    return 0;
}
输入:
abc
def,
输出:
abc
def

getline

ignore

peek

putback

“istream常用函数有哪些”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!


文章名称:istream常用函数有哪些
网站路径:http://mbwzsj.com/article/iioeeg.html

其他资讯

让你的专属顾问为你服务