C++ で CGI を試しています。基本的なものを処理するライブラリがあることは知っていますが、内部で何が起こっているかを知るために、文字列データ型を使用して stdin を解析しようとしました ---> '= と &' を使用してトークン化し、push_back をベクトルにします。最後のステップで、セグメンテーション違反を受け取ります。以下は、ユーザー入力などを取得するために cin>> を使用しているプログラムです..
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
using namespace std;
int main()
{
vector <string> stuff(0);
vector<string>::iterator it;
char* bufferchar;
string buffer;
char str[size];
cout<<"Content-type: text/html\n\n"
<<"<html>"
<<"<head>"
<<"<title>CGI SCRIPT</title>"
<<"</head>"
<<"<body>"
fgets(str,20,stdin); //20 is expect size of content from html form
puts(str);
cout<<"<p>Now to break this guy apart";
int x=0;
bufferchar = strtok(str,"&=");
buffer+=bufferchar;
stuff.push_back(buffer);
while(bufferchar!=NULL){
cout<<bufferchar<<'\n'<<'\n';
bufferchar=strtok(NULL,"&=");
buffer+=bufferchar;
stuff.push_back(buffer);
}
cout<<"<br>ok does the vector iterate ?";
for (it=stuff.begin();it!=stuff.end();++it){
cout<<*it;
cout<<"<br> ok man, next <br><br>";
}
cout<<"</body>";
cout<<"</html>";
}