-1
약 100 줄의 텍스트가 있습니다. 각 줄의 형식은 다음과 같습니다. 1 Gt 1.003
Gt
은 1 ~ 3 자 길이로 변경됩니다. 이 줄을 구문 분석하고 을 문자열로 저장하고 1.003
을 이중으로 저장하고 1
을 삭제할 수 있습니까?이 형식의 문자열에서 데이터를 구문 분석하려면 어떻게해야합니까? 1 Gt 500.85?
약 100 줄의 텍스트가 있습니다. 각 줄의 형식은 다음과 같습니다. 1 Gt 1.003
Gt
은 1 ~ 3 자 길이로 변경됩니다. 이 줄을 구문 분석하고 을 문자열로 저장하고 1.003
을 이중으로 저장하고 1
을 삭제할 수 있습니까?이 형식의 문자열에서 데이터를 구문 분석하려면 어떻게해야합니까? 1 Gt 500.85?
using namespace std;
int discardInt;
string strInput;
double dblInput;
vector<string> strings;
vector<double> doubles;
ifstream infile("filename.txt"); //open your file
while(infile >> discard >> strInput >> dblInput) {
//now discard stores the value 1, which you don't use;
//strInput stores Gt or other 1-3 character long string;
//dblInput stores the double
//operations to store the values that are now in strInput and dblInput
//for example, to push the values into a vector:
strings.push_back(strInput);
doubles.push_back(dblInput);
}
infile.close();
꽤 평범한 물건.
ifstream file(...);
string line;
while (getline(file, line)
{
istringstream buf(line);
int dummy;
string tag;
double val;
buf >> dummy >> tag >> val;
}
tag
는 val
는 1.003
'표준 : regex' 될 것 "GT는"될 것인가? .. –