C 之strtok實例代碼詳解
#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <string.h>
#include <stdlib.h>
using namespace std;
int main()
{
ifstream f("x.cfg");
string str;
while(getline(f,str))
{
if(str[0]==[)
cout<<str<<endl;
else
{
const char* needle="=";
char* ccc=const_cast<char*>(str.c_str());
char* c=strtok(ccc, needle);
if(c)
cout<<"F:"<<c<<" ";
c = strtok(NULL, needle);
if(c)
cout<<"R:"<<c<<endl;
}
}
return 0;
}