| | |
Config file read from '=' sign
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2009
Posts: 39
Reputation:
Solved Threads: 0
Ok I need to know how to set my class to read only the values after the = sign.
Here's my class so far.
Here's my class so far.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <fstream> using namespace std; class Config { int pos; string search; public: char * confname; void configsearch () { fstream filename (confname); while (!filename.eof()) { badsearch: getline (filename,search); pos = search.find("#"); if (pos != -1) { goto badsearch; } cout << search; pos = search.find("="); if (pos != -1) { cout << "\n" << pos; } cout << "\n"; } }; };
Last edited by kelechi96; Apr 17th, 2009 at 1:17 pm.
•
•
Join Date: Sep 2008
Posts: 90
Reputation:
Solved Threads: 12
Look at the code here:
I think you meant:
Another thing is that string::search() returns string::npos if the search function does not find what it was told to find, and not -1, so the code should be:
And one last thing: you can avoid using
if (pos != -1)
{
goto badsearch;
}if (pos == -1)
{
goto badsearch;
}Another thing is that string::search() returns string::npos if the search function does not find what it was told to find, and not -1, so the code should be:
if (pos == string::npos) { goto badsearch; } cout << search; pos = search.find("="); if (pos != string::npos) { cout << "\n" << pos; }
And one last thing: you can avoid using
goto in your 'if' statement by replacing it with the statement continue; - this will jump to the beginning of the while loop:if (pos == string::npos)
{
continue;
} Last edited by unbeatable0; Apr 17th, 2009 at 1:57 pm.
>Where is the border?...
Common sense, of course. Note that I said "avoid listening to" and not "never listen to".
The whole reason we have this "goto is teh EBIL!!!!!" crap is because a bunch of people were mindlessly following orders rather than thinking for themselves.
Common sense, of course. Note that I said "avoid listening to" and not "never listen to".
The whole reason we have this "goto is teh EBIL!!!!!" crap is because a bunch of people were mindlessly following orders rather than thinking for themselves. I'm here to prove you wrong.
>A. Whats wrong with goto
Nothing. The problem is people using it in an undisciplined way such that the code becomes an unruly mess where control flow is difficult to follow.
>B. still dosn't awnser my origonal question
Be patient. When someone is ready to give you an answer, you'll get it. I notice you didn't even bother to thank unbeatable for taking the time to help you. Did you make the suggested changes?
Nothing. The problem is people using it in an undisciplined way such that the code becomes an unruly mess where control flow is difficult to follow.
>B. still dosn't awnser my origonal question
Be patient. When someone is ready to give you an answer, you'll get it. I notice you didn't even bother to thank unbeatable for taking the time to help you. Did you make the suggested changes?
I'm here to prove you wrong.
•
•
Join Date: Apr 2009
Posts: 39
Reputation:
Solved Threads: 0
unbeatable thanks for taking your time to awnser me however firstly I didn't realy need to change my
!= to == because it was supposed to go to the next line if it found a '#' because '#' is a comment sign and I changed goto to continue i don't know how it will affect execution time but realy execution time isn't realy an issue in this project ![]() |
Similar Threads
- Need Help with this code (C++)
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
- Aurora suspected (Viruses, Spyware and other Nasties)
- Help me in username and password validation through accessing the database (ASP.NET)
- Users Locked Out, Gdm Gone Beserk, 14 hours at work. No solution yet (Window and Desktop Managers)
- sourcing a python config file? (Python)
Other Threads in the C++ Forum
- Previous Thread: BigInteger - modpow()
- Next Thread: deleting pointer to an object
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






