---
title: "console 输入输出"
author: "linest"
date: "2012-04-10T17:06:32Z"
tags: []
categories: ["编程语言"]
slug: "console"
draft: false
lastmod: "2012-04-10T17:06:32Z"
id: 1481964
url: "https://linest.iteye.com/blog/1481964"
---

读EOF结尾
scanf返回读出变量数
如果没读出返回-1
EOF就是常量-1

```c

while(scanf("%d %d",&a,&b)!=EOF)
{
}

```



```c++

while(cin>>a>>b)
{
}

```



读字符串整行
scanf以空格分隔
gets以回车分隔


```c

char buf[20];
gets(buf);

```



```c++

string buf;
getline(cin,buf);

char buf[20];
//参数1 数组  参数2 读取个数  参数3 结束符默认'\n'
cin.getline(buf,255,'\n');

```