C++分割字符串

例如:std::string path;   path = path + "*" + s2 + "*" + s4; 

如何得到s2和s4?

                size_t pos = _path.find("*");
		size_t size = _path.size();
		int cnt = 0;
		while (pos != std::string::npos)
		{
			if (cnt==0)
			{
				std::string x = _path.substr(0, pos);
				//resVec.push_back(x);
				setScreenShotPath(x);

				_path = _path.substr(pos + 1, size);
				pos = _path.find("*");
			}
			if (cnt==1)
			{
				std::string x = _path.substr(0, pos);
				//resVec.push_back(x);
				float fLove = atof(x.c_str());
				setTextureWidth(fLove);

				_path = _path.substr(pos + 1, size);
				pos = _path.find("*");
				fLove= atof(_path.c_str());
				setTextureHeight(fLove);
			}
			
			cnt++;

		}

  

 

posted @ 2017-11-09 15:43  唐淼  阅读(238)  评论(0编辑  收藏  举报