開発環境 Microsoft Visual C++ 2010 Express (SP1)
実行環境 Microsoft Windows XP Home Edition (SP3)
プロジェクトの種類 Win32 コンソール アプリケーション
プロジェクト名 test
アプリケーションの種類 コンソール アプリケーション
追加のオプション 空のプロジェクト

vecstr.cpp
#include <stdio.h>
#include <string.h>
 
#include <vector>
#include <string>
 
typedef std::vector<std::string> vecstr;
 
int main()
{
	vecstr vs;
	vecstr::iterator it;
	char str[] = "tako\nika\nmanbo";
	char *p = str;
	char *lf;
 
	while (*p) {
		lf = strchr(p, '\n');
		if (lf == NULL) {
//			printf("[%s]\n", p);
			vs.push_back(p);
			break;
		}
		*lf = '\0';
//		printf("[%s]\n", p);
		vs.push_back(p);
		p = lf + 1;
	}
	for (it = vs.begin(); it != vs.end(); it++) {
		printf("[%s]\n", (*it).c_str());
	}
	return 0;
}
 

出力
[tako]
[ika]
[manbo]
最終更新:2012年09月06日 12:22