私はあなたの例でこれをテストしましたが、これが助けてくれることを願っています!
using namespace std;
/*
When trying to get the 0 after the "id=" in:
\t "<edge id="0" source="0" target="1" />"
subString="id="
surrChar (surrounding character)='\"'
fullString="<edge id="0" source="0" target="1" />"
return="0"
Function will return an empty string if subString was not in fullString
*/
string getValueFromString(string subString, char surrChar, string fullString) {
\t int subStringLength = subString.length();
\t int fullStringLength = fullString.length();
\t /*
\t minus three because after the substring,
\t there will have to be two surrounding characters around your value
\t and at least one character that is your value
\t */
\t int indexToCheckTo = fullStringLength - subStringLength - 3;
\t for(int index = 0; index <= indexToCheckTo; ++index) {
\t \t // sub string in fullString
\t \t string ssInFullString = "";
\t \t // get a substring in the fullString to check if it is
\t \t // the same as subString
\t \t for(int subIndex = index; subIndex < index + subStringLength; ++subIndex) {
\t \t \t ssInFullString += fullString[subIndex];
\t \t }
\t \t // if the substring just obtained is the same as the original substring,
\t \t // and the character after this subString is the surrChar
\t \t if(\t !ssInFullString.compare(subString)
\t \t \t && fullString[index + subStringLength] == surrChar) {
\t \t \t string retString = "";
\t \t \t // start at the index after the surrChar
\t \t \t // go until either you hit the end of the string
\t \t \t \t // or the current char is surrchar
\t \t \t for(\t int subIndex = index + subStringLength + 1;
\t \t \t \t subIndex < fullStringLength && fullString[subIndex] != surrChar;
\t \t \t \t ++subIndex) {
\t \t \t \t retString += fullString[subIndex];
\t \t \t }
\t \t \t return retString;
\t \t }
\t }
\t return "";
}
ちょうどあなたがcstyle sscanf関数を使用することができ整数
に返された値を変換するSTOI(文字列)を使用し、プロジェクトにこれを実装します。 https://www.tutorialspoint.com/c_standard_library/c_function_sscanf.htm – MayurK
この種の入力については、XMLパーサーが役立ちます。http://stackoverflow.com/questions/170686/what-is-the-best-open- xml-parser-for-c – dvnguyen