Created
March 2, 2018 10:44
-
-
Save toya33/9dd4809ea29dbfda416733f54df24771 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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