Last active
February 3, 2016 03:31
-
-
Save ityuhui/65c9ac88b782cce8b4e1 to your computer and use it in GitHub Desktop.
C++ 读取文本文件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iostream> | |
#include <string> | |
int main() | |
{ | |
std::string s; | |
int count = 0; | |
std::ifstream in("ConsoleApplication2.cpp"); | |
if (in.is_open()) { | |
while (!in.eof()) { | |
std::getline(in,s); | |
std::cout << s << std::endl; | |
if (s.length() != 0) { | |
count++; | |
} | |
} | |
std::cout << "The count of non-blank line is: " << count << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment