Skip to content

Instantly share code, notes, and snippets.

@toya33
Created March 2, 2018 10:44
Show Gist options
  • Save toya33/9dd4809ea29dbfda416733f54df24771 to your computer and use it in GitHub Desktop.
Save toya33/9dd4809ea29dbfda416733f54df24771 to your computer and use it in GitHub Desktop.
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
using namespace std;
struct status
{
string protocol;
string statusCode;
string message;
};
int statusLineAnalysis(string line, status* st)
{
vector<std::string> v;
stringstream ss(line);
string buf;
char sep = ' ';
int vSize = 0;
while(getline(ss, buf, sep))
{
v.push_back(buf);
}
vSize = v.size();
// プロトコル
st->protocol = v.at(0);
// ステータスコード
st->statusCode = v.at(1);
// メッセージ
st->message = v.at(2);
for(int i = 3; i < (vSize); i++)
{
st->message = st->message + " " + v.at(i);
}
return 0;
}
int main( )
{
ifstream ifs("HttpHeader.txt");
string statusLine;
string header;
string buf;
getline(ifs, buf);
status st;
statusLineAnalysis(buf, &st);
cout << "プロトコル:" + st.protocol << endl;
cout << "コード:" + st.statusCode << endl;
cout << "メッセージ:" + st.message << endl;
cout << "-------------" << endl;
while(ifs && getline(ifs, buf)) {
cout << buf << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment