Skip to content

Instantly share code, notes, and snippets.

@ityuhui
Last active February 3, 2016 03:31
Show Gist options
  • Save ityuhui/65c9ac88b782cce8b4e1 to your computer and use it in GitHub Desktop.
Save ityuhui/65c9ac88b782cce8b4e1 to your computer and use it in GitHub Desktop.
C++ 读取文本文件
#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