| | |
Please Help me!! please!!!!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2009
Posts: 3
Reputation:
Solved Threads: 0
I have got a log file as follows
The log file has the following format : Date/Time, Severity, Module(the number after the process name is the process id) and finally the diagnostic message as an example :
dd/mm/yyyy HH:mm:ss.mmm Severity Module Message
======================= ======== ====== =======
17-11-2008 17:01:17.590 SUCCESS wmlumberjack.exe:940 System Information. CPU speed
17-11-2008 17:01:22.090 INFORMATION winword.exe:3656 CWSWordAddIn::OnConnection.\WSWordAddIn.cpp(131) : -> VDE
tart
I need to write a code in C++ that is able to filter and display the results based on the severity selected by the user. As an example if the user selects to see only WARNINGS, the application should only display the lines in the log file that contain the WARNING attribute.
The log file has the following format : Date/Time, Severity, Module(the number after the process name is the process id) and finally the diagnostic message as an example :
dd/mm/yyyy HH:mm:ss.mmm Severity Module Message
======================= ======== ====== =======
17-11-2008 17:01:17.590 SUCCESS wmlumberjack.exe:940 System Information. CPU speed
17-11-2008 17:01:22.090 INFORMATION winword.exe:3656 CWSWordAddIn::OnConnection.\WSWordAddIn.cpp(131) : -> VDE
tart I need to write a code in C++ that is able to filter and display the results based on the severity selected by the user. As an example if the user selects to see only WARNINGS, the application should only display the lines in the log file that contain the WARNING attribute.
Well, that's not too difficult. You could open the file, read it line-by-line, and print only those lines which contain the word "WARNING", for example. If you wanted to be more robust, you could separate out the column and compare that.
Some code that may help:
And for columns, you could use stringstreams.
[edit] By the way, don't say "URGENT HELP NEEDED IMMEDIATELY PLZ!!!!!111" in the title. It's not going to make people read it any faster. [/edit]
Some code that may help:
C++ Syntax (Toggle Plain Text)
std::string text = "A message of some sort."; if(text.find("message")) { std::cout << "The string contains the word 'message'\n"; }
C++ Syntax (Toggle Plain Text)
#include <sstream> // for stringstreams std::string line; // this is read from a file std::istringstream stream(line); std::string col1, col2, col3; stream >> col1 >> col2 >> col3; if(col3 == "WARNING") /* ... */
[edit] By the way, don't say "URGENT HELP NEEDED IMMEDIATELY PLZ!!!!!111" in the title. It's not going to make people read it any faster. [/edit]
Last edited by dwks; Jun 8th, 2009 at 6:23 pm.
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
I've really told you all you need to know. I'll give you some more details, but you'll have to do some searching . . . .
Three steps.
Three steps.
- Open the file. You use ifstream to do this, it's not hard. http://www.cplusplus.com/reference/i...ream/ifstream/
- Read lines from the file, one at a time. Use getline() for this.
- If the line has "WARNING", print it. I showed you how to do this in the previous post.
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
•
•
Join Date: Jun 2009
Posts: 3
Reputation:
Solved Threads: 0
But how do I capture input from the user to select the severity???
the log file looks somewhat like below!!
dd/mm/yyyy HH:mm:ss.mmm Severity Module Message
======================= ======== ====== =======
17-11-2008 17:01:17.590 SUCCESS wmlumberjack.exe:940 System Information. CPU speed
17-11-2008 17:01:22.090 INFORMATION winword.exe:3656 CWSWordAddIn::OnConnection.\WSWordAddIn.cpp(131) : -> VDE
tart
17-11-2008 17:01:23.996 WARNING winword.exe:3656 Workshare Failed to query Installation Validation value!
17-11-2008 17:01:45.903 ERROR winword.exe:664 WordCustomProperty .\WordCustomProperty.cpp(81) : -> GetCustomProperty
the log file looks somewhat like below!!
dd/mm/yyyy HH:mm:ss.mmm Severity Module Message
======================= ======== ====== =======
17-11-2008 17:01:17.590 SUCCESS wmlumberjack.exe:940 System Information. CPU speed
17-11-2008 17:01:22.090 INFORMATION winword.exe:3656 CWSWordAddIn::OnConnection.\WSWordAddIn.cpp(131) : -> VDE
tart 17-11-2008 17:01:23.996 WARNING winword.exe:3656 Workshare Failed to query Installation Validation value!
17-11-2008 17:01:45.903 ERROR winword.exe:664 WordCustomProperty .\WordCustomProperty.cpp(81) : -> GetCustomProperty
use a cout statement asking the user what type of severity they want like
c++ Syntax (Toggle Plain Text)
//... std::string choice; cout << "Please enter the severity you want.\n"; cout << "Your choices are: warning, success, information, and error: "; cin >> choice //... }
if you write
If your thread is solved please mark it as solved
using namespace std; you do not need to write std::something in your program.If your thread is solved please mark it as solved
![]() |
Other Threads in the C++ Forum
- Previous Thread: Inserting unicode into console
- Next Thread: encrypting text speed
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





