| | |
ignoring to a specific sequence of characters
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2009
Posts: 1
Reputation:
Solved Threads: 0
I am trying to write a program that will open a specific file and go through it, writing the data I need to another file. Everytime the tag 'Step 4[2]' comes up I need to get the next two numbers and write them to a seperate file. (the purpose is to get the data to create a load displacement curve for an atomic simulation we're running) The results file is periodic, meaning that it repeats itself many times so the inefficient way would be to figure out how many lines are repeated and ignore that many before getting the data. The problem is, each simulation will have a different amount of lines needing to be skipped so it would take a lot of work to change the code for each different simulation. I'm hoping to write a more general code that can be used for all the simulations.
So here is my question: is there any way to ignore to a specific sequence of characters? (ie: ignore until it hits 'Step 4[2]')
I tried "inStream.ignore(4000, 'Step 4[2]');" but it give me errors because 'Step 4[2]' is more than one character. Is it possible to ignore until a specific sequence of characters instead of to a single character? Any help is GREATLY appreciated!!
So here is my question: is there any way to ignore to a specific sequence of characters? (ie: ignore until it hits 'Step 4[2]')
I tried "inStream.ignore(4000, 'Step 4[2]');" but it give me errors because 'Step 4[2]' is more than one character. Is it possible to ignore until a specific sequence of characters instead of to a single character? Any help is GREATLY appreciated!!
Try to adopt this improvisation:
C++ Syntax (Toggle Plain Text)
const size_t allbut = std::numeric_limits<int>::max(); bool overStep(std::istream& in) { char c; while (in.ignore(allbut,'S')) { do if (in.get(c) && c == 't' && in.get(c) && c == 'e' && in.get(c) && c == 'p' && in.get(c) && c == ' ' && in.get(c) && c == '[' && in.get(c) && c == '2' && in.get(c) && c == ']') return true; while (in && c == 'S'); } return false; } // mini-test int main() { std::ifstream fin("step.txt"); std::string after; while (overStep(fin)) { if (fin >> after) std::cout << after << '\n'; } return 0; }
Last edited by ArkM; Jun 15th, 2009 at 6:37 pm.
![]() |
Similar Threads
- Handling Exceptions - Program ignoring specific characters for if statements (C++)
- Its a matter of converting it i guess... (Pascal and Delphi)
- Field with UPPERCASE but without soecial characters (JavaScript / DHTML / AJAX)
- Not waiting for input during loop (C++)
- detecting '\n' without using getline (C++)
- tokenization of file input (Java)
- what's with gcc? (C++)
- Sequence of device driver loading (Troubleshooting Dead Machines)
Other Threads in the C++ Forum
- Previous Thread: installing GTK+ on Ubuntu
- Next Thread: burn a the whole file into CD ?
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux 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 return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






