How to detect a text in output?
For example: I get output like this (2nd below) and I want to output
HTML Code:
cout << new8.xml <<endl;
after. Is it possible?
HTML Code:
<file>new0.xml</file>
<file>new1.xml</file>
<file>new2.xml</file>
<file>new3.xml</file>
<file>new4.xml</file>
<file>new5.xml</file>
<file>new6.xml</file>
<file>new7.xml</file>
Re: How to detect a text in output?
Quote:
Originally Posted by
prako2
For example: I get output like this (2nd below) and I want to output
Code:
cout << new8.xml <<endl;
after. Is it possible?
Code:
<file>new0.xml</file>
<file>new1.xml</file>
<file>new2.xml</file>
<file>new3.xml</file>
<file>new4.xml</file>
<file>new5.xml</file>
<file>new6.xml</file>
<file>new7.xml</file>
Did you already try it?
Re: How to detect a text in output?
No, because I don't know how to achieve this. But I probably could if I know how to find a file with the biggest number.
Re: How to detect a text in output?
Quote:
Originally Posted by
prako2
No, because I don't know how to achieve this.
"achieve" what? Output?
Then make first the "second" output, and then the "first" one!
Re: How to detect a text in output?
This is not exactly what I want. I want to find a file with the biggest number, increment it by 1 and then output.
Re: How to detect a text in output?
Quote:
Originally Posted by
prako2
... I want to find a file with the biggest number, increment it by 1 and then output.
And with what part of this task do you have a problem? And what is this problem?
Re: How to detect a text in output?
This:
Quote:
Originally Posted by
prako2
But I probably could if I know how to find a file with the biggest number.
Re: How to detect a text in output?
Well, you could use CFileFind class to perform file searches (usually, among some file types).
Then you open every file and read it content up to the end to find the "biggest number" and save this number together with the file name in some buffer.
Now (after the search with CFileFind completed) you choose the biggest number and the corresponding file name.
Re: How to detect a text in output?
Thanks, but I want to do it directly from output text.
Re: How to detect a text in output?
What do you mean by "directly from output text"? :confused:
Re: How to detect a text in output?
I think he means something like this:
Code:
const string out = "<file>new0.xml</file>
<file>new1.xml</file>
<file>new2.xml</file>
<file>new3.xml</file>
<file>new4.xml</file>
<file>new5.xml</file>
<file>new6.xml</file>
<file>new7.xml</file>";
int hghnum = getHighnum(out);
where in this case hghnum would be 7
??
Re: How to detect a text in output?
Wow 2kaud! You definitely have a crystal ball in your hands! :thumb:;)
But I don't... :cry:
Re: How to detect a text in output?
If my crystal ball gazing is somewhere near the mark, then consider:
Code:
#include <string>
#include <iostream>
#include <charconv>
#include <algorithm>
using namespace std;
size_t getHighnum(const string& out, const string& pre)
{
size_t maxnum = 0;
const auto strt = out.data() + pre.size();
for (size_t off = 0; (off = out.find(pre, off)) != string::npos; off += pre.size()) {
size_t num = 0;
from_chars(strt + off, strt + off + out.size(), num);
maxnum = max(maxnum, num);
}
return maxnum;
}
int main()
{
const string out = R"(<file>new0.xml</file>
<file>new1.xml</file>
<file>new2.xml</file>
<file>new3.xml</file>
<file>new4.xml</file>
<file>new5.xml</file>
<file>new6.xml</file>
<file>new7.xml</file>)";
size_t hghnum = getHighnum(out, "new");
cout << "Highest number found is " << hghnum << endl;
}
Re: How to detect a text in output?
@OP Hmm, invalid xml, not off to a good start.
Re: How to detect a text in output?
Thank you 2kaud, very useful.