Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Java 中很容易完成了一些事情,但是以下的 C++ 版本是什么:
while (in.hasNextLine()) { String line = in.nextLine(); if (i == 13) { i++; break; } i++; }
这是 nextLine 部分,我似乎找不到 C++ 等价物
std::ifstream in("Path\\To\\File.txt"); std::string line; while (std::getline(in, line)) { if (i++ == 13) { break; } }
假设in是一个文件流
in
#include <sstream> #include <string> while (std::getline(in, line)) { // Do your thing }