2015-11-21 20 views
-1

對不起,如果我簡單介紹了這段代碼很麻煩。 我想基本上解析文件「question.txt」 每次我看到了一段時間,我希望有一個新的生產線 基本上是:。使用C++分隔句子,每個句點後

嘿吉姆(新線)

哎恬(新行)

int main(){ 

    ifstream openQuiz; 
    openQuiz.open("questions.txt"); 
    string line; 
    //int count = 0; 
    //Check for errors 
    if (openQuiz.fail()) { 
     cerr << "Error opening file" << endl; 
    } 

    //Reading from beginning to ending; 
    while (!openQuiz.eof()) { 



    } 

    openQuiz.close(); 
    return 0; 
} 
+0

C不是C++不是C!請不要爲C++問題添加C標記。 – Olaf

回答

1
#include <iostream> 
#include <fstream> 
using namespace std; 

int main() { 
    ifstream f("file.txt"); 
    char c; 
    while (f.get(c)) { 
    cout << c; 
    if (c=='.') cout << endl; 
    } 

    return 0; 
} 

這個怎麼樣的嗎? 您可以在此閱讀更多關於std::istream::get()http://www.cplusplus.com/reference/istream/istream/get/

+0

感謝資源夥伴!我會盡快嘗試,看看它是否正是我所需要的。因爲我在網上找到的是人們在談論使用「ss」的流,這是混淆的方式 – user3453661

1

您可以使用fstream而不是ifstream。區別在於fstreams可以同時進行輸入和輸出。 然後,你可以簡單地閱讀字符一個接一個。每當你讀到'。'時寫一個換行符。

相關問題