Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * DISCLAIMER: Este codigo utiliza archivos... cualquier perdida de informacion es responsabilidad solamente de quien usa este
- * programa.
- * DISCLAIMER: This programs works with files. By using this programm, you accept that the author of the code is not responsible
- *of any damage to your files.
- * Para compilar: g++ main.cpp
- * Para utilizar: En una terminal, escribe ./parse_physics_problems <Archivo.tex
- * Para simplificar el codigo, lo programe para que lea de la "entrada estandard" que es un termino muy de unix
- * */
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <sstream>
- using namespace std;
- const char* PROBLEM_BEGIN = "\\begin{prob}";
- const char* PROBLEM_END = "\\end{prob}";
- int main(int argc, char **argv) {
- if (argc > 1){
- cout << "usage: parse_physics_problems" << endl;
- cout << "Reads physics problems from stdin" << endl;
- return 1;
- }
- int file_count = 0;
- string line;
- ofstream stream;
- stringstream ss;
- while (!cin.eof()){
- getline(cin, line);
- if (line == PROBLEM_BEGIN){
- file_count++;
- ss << file_count << "-test.prob" << ends;
- stream.open(ss.str().c_str());
- }
- else if (line == PROBLEM_END){
- if (!stream.is_open()){
- cout << "Error parseando el archivo!" << endl;
- }
- stream.close();
- //ss.str("");
- ss.seekp(0);//This is tricky, but avoids some memory allocations.
- }
- else {
- if (stream.is_open())
- stream << line << endl;
- else
- cout << line << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment