-
September 5th, 2019, 06:25 AM
#1
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>
-
September 5th, 2019, 06:36 AM
#2
Re: How to detect a text in output?
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?
Victor Nijegorodov
-
September 5th, 2019, 06:39 AM
#3
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.
-
September 5th, 2019, 06:42 AM
#4
Re: How to detect a text in output?
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!
Victor Nijegorodov
-
September 5th, 2019, 06:49 AM
#5
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.
-
September 5th, 2019, 06:57 AM
#6
Re: How to detect a text in output?
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?
Victor Nijegorodov
-
September 5th, 2019, 07:04 AM
#7
Re: How to detect a text in output?
This:
Originally Posted by prako2
But I probably could if I know how to find a file with the biggest number.
-
September 5th, 2019, 07:15 AM
#8
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.
Victor Nijegorodov
-
September 5th, 2019, 07:24 AM
#9
Re: How to detect a text in output?
Thanks, but I want to do it directly from output text.
-
September 5th, 2019, 07:27 AM
#10
Re: How to detect a text in output?
What do you mean by "directly from output text"?
Victor Nijegorodov
-
September 5th, 2019, 07:54 AM
#11
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
??
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
September 5th, 2019, 07:59 AM
#12
Re: How to detect a text in output?
Wow 2kaud! You definitely have a crystal ball in your hands!
But I don't...
Victor Nijegorodov
-
September 5th, 2019, 08:17 AM
#13
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;
}
Last edited by 2kaud; September 5th, 2019 at 09:12 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
September 6th, 2019, 12:54 AM
#14
Re: How to detect a text in output?
@OP Hmm, invalid xml, not off to a good start.
-
September 9th, 2019, 05:24 AM
#15
Re: How to detect a text in output?
Thank you 2kaud, very useful.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|