// fortest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <string>
#include <string.h>
#include <map>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
int main()
{
std::istringstream is("123");
std::cout << "--------------------读取一个\n";
is.get();
std::cout << is.good() << std::endl;
std::cout << is.eof() << std::endl;
std::cout << is.fail() << std::endl;
std::cout << is.bad() << std::endl;
std::cout << "--------------------读取剩下的\n";
char *buf = (char *)malloc(3 + 1);
memset(buf, 0, 4);
is.read(buf, 2);
printf("%s\n", buf);
std::cout << is.good()<< std::endl;
std::cout << is.eof() << std::endl;
std::cout << is.fail() << std::endl;
std::cout << is.bad()<<std::endl;
std::cout << "--------------------再读取\n";
is.get();
std::cout << is.good() << std::endl;
std::cout << is.eof() << std::endl;
std::cout << is.fail() << std::endl;
std::cout << is.bad() << std::endl;
std::cout << "--------------------再读取\n";
is.get();
std::cout << is.good() << std::endl;
std::cout << is.eof() << std::endl;
std::cout << is.fail() << std::endl;
std::cout << is.bad() << std::endl;
free(buf);
return 0;
}
/*
--------------------读取一个
1
0
0
0
--------------------读取剩下的
23
1
0
0
0
--------------------再读取
0
1
1
0
--------------------再读取
0
1
1
0
请按任意键继续. . .
*/
c++ good() eof() fail() bad()
最新推荐文章于 2023-11-01 15:01:12 发布