掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
fgets後のmap処理について (ID:57288)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
整理しました。 #include <stdio.h> #include <string> #include <map> int main(void){ FILE* fp; char buffer[250]; char *token; std::string strKey; //mapキー std::string strValue; //map値 std::map<std::string, std::string> mapdata; fp = fopen("message.csv","r"); if( !fp ){ return 1; } while( fgets( buffer, sizeof(buffer), fp ) != NULL ){ fgets(buffer,sizeof(buffer),fp); token = strtok(buffer,","); strKey = token; token = strtok( NULL, "\n" ); strValue = token; mapdata[ strKey ] = strValue; mapdata.insert(std::pair<std::string, std::string> (strKey,strValue)); } fclose(fp); std::map<std::string, std::string>::const_iterator p; for(p = mapdata.begin(); p != mapdata.end(); p++){ printf( "%s", p->second.c_str() ); } p = mapdata.find(strKey); if(p != mapdata.end()){ printf( "%s", p->second.c_str() ); } else { printf("not_data"); } return 0; } 今はmainに書いてある処理を 関数をrenshu.hというヘッダーファイルを作って mainにincludeさせて簡単な単体テストをやりたいのですが、 int main(void)にした場合、 再度引数を定義しないといけないでしょうか??
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.