- /*
- * File: main2.cpp
- * Author: Vicky
- *
- * Created on 2011年11月25日, 上午10:16
- */
- #include <iostream>
- #include <stdio.h>
- #include <cstring>
- #include <stdlib.h>
- /*
- *
- */
- int main(void) {
- std::cout << "both getline the different !" << std::endl;
- int ret;
- FILE* pf;
- pf = fopen("./main.cpp", "r");
- if (pf == NULL) {
- perror("can not open file './main.cpp'");
- return 1;
- }
- size_t size;
- ssize_t read;
- char* line;
- line = (char*) malloc(64); // 如果分配太小的话,会出错
- // 这个是stdio的getline
- while ((read = getline(&line,&size,pf)) != EOF) {
- std::cout << line << std::endl;
- }
- line = NULL;
- std::cout << "inter something ,‘exit’!" << std::endl;
- std::string str;
- while (std::getline(std::cin,str) && str != "exit") {
- std::cout << ">>" << str << std::endl;
- }
- ret = fclose(pf);
- if (ret != 0) {
- perror("can not close file './main.cpp'");
- return 1;
- }
- return 0;
- }