#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
using namespace std;
void readFile()
{
const char* filePath = "D:\\guiCode\\leeteCode\\sstreamTest\\sstreamTest\\file.txt";
ifstream readStream(filePath,ios_base::app);
if (!readStream.is_open())
{
printf("file open failed %s",filePath);
return;
}
char szOneLine[512];
memset(szOneLine,0,512);
while (!readStream.eof())
{
readStream.getline(szOneLine, 512);
string strOneLine = szOneLine;
if (strOneLine.size() == 0)
{
continue;
}
//decode quickly content from str,and value type no limit
stringstream strStream(strOneLine);
//istringstream strStream(strOneLine);
int value;
strStream >> value;
std::cout << "value:" << value << std::endl;
strStream >> value;
std::cout << "value:" << value << std::endl;
string result;
strStream >> result;
std::cout << "result:" << result.c_str() << std::endl;
}
//method 2 this method can get the format of the content from file
//stringstream strStream;
//strStream << readStream.rdbuf();
//int value;
//strStream >> value;
//std::cout << "value:" << value << std::endl;
//strStream >> value;
//std::cout << "value:" << value << std::endl;
//string result;
//strStream >> result;
//std::cout << "result:" << result.c_str() << std::endl;
//result=strStream.str();
}
int main()
{
readFile();
return 0;
}
08-10
4629
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交