admin管理员组文章数量:1321430
I am trying to make a program that can take a string from a file, and convert it to 4 predefined integers.
For now, I am attempting the stage after extracting the line from the document, to split it up into the wanted parts.
""
were creating issues, but it was easily solved by std::replace
'ing the offending characters. Eventually, the source of the string will be directly from the file, but when inputting it manually, it automatically breaks the terminal:
string: <bounds minlat="51.4374338" minlon="-0.2090608" maxlat="51.5663602" maxlon="-0.0019455"/><bounds minlat="51.4374338" minlon="-0.2090608" maxlat="51.5663602" maxlon="-0.0019455"/>
:bounds
And somehow, with no help, it breaks in a weirder manner:
string: <bounds minlat="51.4374338" minlon="-0.2090608" maxlat="51.5663602" maxlon="-0.0019455"/><bounds minlat="51.4374338" minlon="-0.2090608" maxlat="51.5663602" maxlon="-0.0019455"/>
<bounds
If someone has an indication of how to approach this, I would be grateful. Googling "Input sanatisation" only gives ignoring numbers and special characters, which this input still breaks.
Full experimentation code below, the used input is in the //comment
:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
// <bounds minlat="51.4374338" minlon="-0.2090608" maxlat="51.5663602" maxlon="-0.0019455"/>
string line6;
cout << "string: "; cin >> line6;
std::replace( line6.begin(), line6.end(), '<', ':');
std::replace( line6.begin(), line6.end(), '>', ';');
std::replace( line6.begin(), line6.end(), '"', '_');
cout << "\n" << line6;
return 0;
}
本文标签:
版权声明:本文标题:c++ - How do I ignore special characters, in this case <, >, and "", in a string that I need to 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1737170546a1965600.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论