3,882
社区成员
发帖
与我相关
我的任务
分享
inline static void split(
IN const string& s_value,
IN const TCHAR& delim,
OUT vector<string>& items
)
{
stringstream stream(s_value);
string item;
while(std::getline(stream, item, delim))
{
items.push_back(trim(item));
}
stream.str(_T(""));
}
代码2
inline void load(
IN const string& sPath
)
{
fstream file;
file.imbue(std::locale("chs"));
file.open(sPath.c_str());
string sSection;
string sLine;
map<wstring, wstring> mapLine;
const TCHAR* szMarks = _T("#;");
while(std::getline(file, sLine))
{
filt(sLine, szMarks);
if(sLine.empty())
{
continue;
}
if(sLine[0] == _T('['))
{
string::size_type index = sLine.find_last_of(_T(']'));
sSection = (string::npos == index ? sLine.substr(1) :sLine.substr(1, index - 1));
continue;
}
vector<string> items;
split(sLine, _T('='), items);
string sKey = trim(items[0]);
string sValue;
if(items.size() > 1)
{
sValue = trim(items[1]);
}
setValue(sSection, sKey, sValue);
}
file.close();
}
ifstream ifs("test.txt");
if(!ifs) return 0;
string s;
getline(ifs,s);
int n;
double dist,x,y,z;
while(ifs>>n>>dist>>x>>y>>z){
// add code
}