请问getchar()到底是怎么用,能不能举个例子

刚刚做到一道题:
输入有多行数据,每行有若干整数,这些整数数以空格分割,请分别求出每行整数的和。
输出的每行对应输入的每行,每行一个数字,即为输入的一行整数之和。
提示用getchar。
如:input:100 100 4
34 34
output:204
68

可是这玩意怎么用,网上写的那些,额,文字描述看得懂,实际操作并不会写。
比如这道题应该怎样写?
是否用到while循环?用了之后,发现始终只能用getchar获得第一个数字,怎么让它往后读取,这个循环怎么写?
还有。获取到换行的转义符之后,怎么让它继续获取第二行的内容?
麻烦用C++语言说明一下。

#include <stdio.h>
int main(void)
{
int c;
/* Note that getchar reads from stdin and
is line buffered; this means it will
not return until you press ENTER. */
while ((c = getchar()) != '\n')
printf("%c", c);
return 0;
}

就是当你输入的字符不是回车的时候,就会打印出这个字符,如果你输入的是回车,那么就会退出while循环,其实就是从标准的输入流中读取一个字符的意思。

getchar用法: http://baike.baidu.com/link?url=XWyrboL4Ox3SwmervYM7Y6X_OgmDWMU7ntA504zsEn2gqnp-Orhs54gyiwLuUDSkwBdvPMzD43YP_vaYRm492_

 #include<stdio.h>

int main(void)
{
    int n,sum;

    while(1)
    {
        sum=0;
        do
        {
            scanf("%d",&n);
            sum+=n;
        }while(getchar()!='\n');
        printf("%d\n",sum);
    }

    return 0;
}

#include
#include
#include
#include
#include
using namespace std;

void main()
{
while( true )
{
vector< char > arrayContainer;
char c = 0;
while( ( c = getchar() ) != '\n' )
{
arrayContainer.push_back( c );
}
int number = 0;
string strNumber = "";
stringstream sstream;
unsigned int uIndex = 0;
while( uIndex < arrayContainer.size() )
{
string strTmp = "";
if( arrayContainer.at( uIndex ) == ' ' )
{
arrayContainer.at( uIndex ) = ',';
}
sstream << arrayContainer.at( uIndex );
sstream >> strTmp;
sstream.clear();
strNumber += strTmp;
uIndex++;
}
vector< int > sumContainer;
unsigned int uStrIndex = 0;
unsigned int uStartIndex = 0;
while( true )
{
unsigned int uIndexTmp = 0;
while( strNumber.substr( uStrIndex, 1 ) != "," && uStrIndex < strNumber.size() )
{
uIndexTmp++;
uStrIndex++;
}
int iNumberTmp = 0;
sstream << strNumber.substr( uStartIndex, uIndexTmp );
sstream >> iNumberTmp;
sstream.clear();
sumContainer.push_back( iNumberTmp );
uStrIndex++;
uStartIndex = uStrIndex;
if( uStrIndex >= strNumber.size() )
{
break;
}
}
int iSum = 0;
while( !sumContainer.empty() )
{
iSum += sumContainer.back();
sumContainer.pop_back();
}
cout << iSum <<endl;
}
}

搞定,如输入:100 12 10, 则输出:122, 这是个循环,所以输出后你如果还想输入其他的数据就按之前的格式继续输入。代码不易,望采纳。

其实可以用getline();

getline(cin,a);//读入到字符数组a中