3 回答

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊
std::ifstream t("file.txt");std::stringstream buffer;buffer << t.rdbuf();
buffer.str()
.
std::ifstream t("file.txt");t.seekg(0, std::ios::end);size_t size = t.tellg();std::string buffer(size, ' ');t.seekg(0);t.read(&buffer[0], size);

TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊
#include <fstream>#include <iostream>#include <sstream> //std::stringstreammain(){ std::ifstream inFile; inFile.open("inFileName"); //open the input file std::stringstream strStream; strStream << inFile.rdbuf(); //read the file std::string str = strStream.str(); //str holds the content of the file std::cout << str << std::endl; //you can do anything with the string!!!}
- 3 回答
- 0 關(guān)注
- 716 瀏覽
添加回答
舉報(bào)