C++ :: Parsing A Text File - Detect When Certain Compilation Condition Begins
Dec 8, 2014
I'm parsing a text file, and I'd like to detect when a certain Compilation Condition - i.e. #ifdef - begins. The challenge is, that the condition can take any of the following patterns:
#ifdef (FLAG)
#if defined (FLAG)
#if (defined (FLAG))
(And perhaps I missed more)
I'd of course need to treat them all the same, as they are indeed the same. How would you know to treat them all the same?
I need to parse the file in such a way that I can create a filesystem hierarchy as if I were enumerating files/directories. Ultimately I want to add these to a tree gui control with everything under its proper node without duplicating anything. It should look roughly like so:
dir -file -dir -file -dir -file
I can open the file and add nodes/children to the tree control but how should I go about doing the actual parsing? How can I find a filename and say "this belongs under this node"? I want to do this efficient as possible even if I must use multiple threads.
1. first my professor required me NOT to change the MAIN function(because he made it)
2. I have to make 3 getlogs() STRING FUNCTIONS:
a. string getlogs(); - accepts no paramters, SHOWS ALL THE CONTENTS OF TEXT FILE b. string getLogs(const string & a); - accepts 1 parameter -SHOWS ONLY THE LINE WHICH CONTAINS THE SPECIFIED DATE FROM MAIN FUNCTION which is "2014-08-01" c. string getLogs(const string & b, const string & c); - accepts 2 parameters, SHOWS ONLY THE LINES FROM THE DATE START to DATE END specified at THE MAIN FUNCTION which is date start-"2014-08-01";DateEnd = "2014-08-10";
I'm parsing an xml file full of payslips and using the data in another application. I've got it all working but I suspect it isn't the most elegant piece of code. I run through the xml file finding a series of "Text" attributes/elements" and then I run through it again finding a series of "Field" attributes/elements, Here is a sample of the code:
// // Get all the Text attributes & Elements // foreach (XElement xtxt in xdoc.Descendants(ns + "Text"))
[Code]...
This works fine, I extract all the data I'm interested in and go to do my thing with it. However I really need to know when each record ends and I was doing that by looking for "Text24" in the text fields and "EeRef2" in the field fields, which wasn't very elegant in the first place. Then a "Text16" was added to end of each record which was fine I could just look for "Text16" but now it's apparent that "Text16" isn't always there. I've got it all working for now but I'd prefer to process one record at a time i.e. extract all the "Text" & "Field" values for one record, do whatever I need to do with it, update the xml file to indicate this progress ( if possible ) and then move on to the next record. I've attached a sample of the xml but basically is has the following structure :
(OS Windows)how do i detect when a file has been changed ? do i need to monitor this file and check the last modified date&time? (how do i do this?) furthermore how do i detect a certain application launch?
If let's say I key in 2, it will search for the id=2 and delete the whole line and the id of banana which is orignially 3, will become 2 and orange which is orignally 4 will become 3 etc.
I researched on how it can be done and most suggested to put inside a vector and fout the line.
I know how to put the values in the vector but how should I go about searching for the id and if the id is found it will delete that line inside the file.
Code: ofstream fout; ifstream readFile("fruit.txt"); while (getline(readFile, line)) {
I have this file that I would like to read into a multidimenstional array in c#: file. If I take the first set of lines as a first example, I would like the print_r to look something like this:
I have a large binary file (84GB) that needs to be broken down into smaller file sizes (~1GB to 8GB) for analysis. The binary file is on a 32-bit machine and cannot be copied to another machine for analysis. The PC has Visual Studio 6.0 and is not upgradable. My issue is I'm using the following generic code to create the smaller files.
fseek(file, start, SEEK_SET); end = start + (variable based on file size); fseek(file, end, SEEK_SET); for (i=start; i<end; i++) { if(!feof(f)) { byte = fgetc(f); fputc(byte,new_file); } }
However, on a 32-bit machine, the iterator can only count up to ~2billion. Which means that I'm unable to copy anything past ~2GB. My original idea was to delete from the large binary file as I read from it so that I can reset the iterator on every read. However, I haven't come across a way to delete binary file entries.
Is there any other way that to break down a large binary file into smaller units? Or is there a way to delete binary file entries in sections or per entry?
On a 64-bit machine I could use _fseeki64. I've been reading that some versions of Visual 6.0 are capable of supporting 64-bit numbers but when using _fseeki64 or _lseeki64 on this machine its an "undeclared identifier"
const string ABC = " A B C D A 1 -1 2 14 B 0 -2 -4 8 C 6 2 2 3
" so if i have it as a string stream and then loop through each line like this:
Code: istringstream in (ABC); for (string line; getline(in, line); ){ vector<char> vec(line.begin(), line.end()); for (int i = 0; i< vec.size(); i++) cout << vec[i] << " "; }
I get my strings chopped into characters. but how to chop it into "meaningful" characters so that -1 is not - and 1. is there any quick way for that to happen ??
I have been attempting to store mathematical functions in a file by parsing them into a linked list with a variable sized char ** array as my storage device. I have ran into problems with the memory management detail. The program crashes before output is flushed to the console, so printf() wasn't a debugging option. Neither is my actual debugger, since it seems to get a SIGTRAP every time. I have my warnings turned all the way up, but no errors or warnings are appearing. The part I know works is the actual code that opens the file and gets a line from the file. As far as the two functions that implement the linked list, that is most likely where the problem lies. My current attempt is basically to store the size of the dynamic array in the structure and keep resizing it until there are no more tokens. Then I will store the number of elements of the array in the structure and move on to the next node.
I am parsing a binary data file by casting a buffer to a struct. It seems to work really well apart from this one double which is always being accessed two bytes off, despite being in the correct place.
If I attempt to print GROSS using printf("%f", row->GROSS) I get 0.0000. However, if I change the type of GROSS to char[8] and then use the following code, I am presented with the correct number...
Code:
typedef struct example { double d; }
example; example *blah = (example*)row->GROSS; printf("%f", blah->d);
i am just making some new programmings and testing it. But every time after compile and run The dos window is closing and again I have to compile And run command so i want The dos windows should prompt me for next input rather than closing.
I need to have an object of class A that doesn't have a default constructor in another class, B:
Code: class A; //This is in a separate header file class B { private:A a;};
The problem is that it won't compile without a default constructor. I'm not allowed to define a default constructor, and the A object in class B has to be private so I can't initialize A a in public.
I also can't change the prototype in the interface to something like
A(int a = 0, int b = 0);
since one of the requirements is that if an object of class A is declared in main, it must not compile due to not having a default constructor. So what can I do to make class B work and compile?
Another question I have is why is this valid:
Code: class A; //#include "A.h" is in the implementation file so it compiles. class B { private:A* a;}; But not this: Code: class A;
class B { private:A a;};
This is for a project that I probably won't be able to turn in on time, but I care more about how to do this right than turning it in for full points.
Now why does defining the if condition as if(pow(i,2) + pow(j,2) == pow(k,2)) doesnt work (ie. doesn't print anything) while defining it as if(i*i + j*j == k*k) works flawlessly - by working I mean printing out single set of 3 numbers.
I am working on one application that requires extensive logging so I want to create a log file of each day during execution.
I tried easylogging++ but i am unable to use into multiple files. If i try to use in other file. I get compilation errors of using same functions or methods already defined.
How can i use macro to hide the implementation of logging in one class to other ??
I've been writing a game engine in C++ for a little over a year now, and its been really fun so far. I've been focusing on windows support for now (using Visual Studio and MSVC) but I'd like to leave the possibility of Linux and Mac support open. As a test, I recently compiled a small portion of my reflection system in Clang, to make sure it all still worked (since I consider that the most advanced portion of my codebase, though I'm pretty sure its all standard C++11). Anyway, I got some strange errors regarding undefined identifiers in template functions, and I managed to isolate the issue in the code below:
Clang throws an error about 'TypeInfo' being undefined when 'DoSomething()' is compiled. However, MSVC compiles the code above without so much as a warning.
This goes against my understanding of how template functions/classes were compiled. I always thought that Undefined symbols were not an issue in templates, as long as they were defined by the time the template was instantiated. Whats the issue here? If in fact MSVC has been doing some non-standard stuff, that's pretty unfortunate for me if I want Linux support, as I'll have to do some serious backflips to resolve all the issues with this in my headers and stuff (I can't be the only one in thinking the current state of C++ with headers and forward-decelerations is just awful to work with).
I want to do conditional compilation based on whether it is windows 7 or windows 8. Here is the code below.
#if (_WIN32_WINNT >= 0x0602) //Condition to check whether it windows 7 or 8 .Based on this we can load msxml 3 or 6. #import <msxml6.dll> #else #import <msxml3.dll> #endif
Im building the above code in windows 8 machine.
Issue here is _WIN32_WINNT should have a value 0x0602, it means it is running in windows 8 machine.Instead it has a value 0x0601 (Means it is taking windows version as windows 7 defined in sdkddkver.h).Im not sure after installing windows 8 sdk im not able to see any include or lib files in the path below C:Program Files (x86)Microsoft SDKsWindowsv8.0A . but i can see all include and lib files of sdk version v7.0A available although i did not installed it.
This is my question : Define a class named HOUSING in C++ with the following descriptions:
Private members REG_NO integer(Ranges 10 - 1000) NAME Array of characters(String) TYPE Character COST Float
Public Members -Function Read_Data( ) to read an object of HOUSING type -Function Display() to display the details of an object -Function Draw Nos( ) to choose and display the details of 2 houses selected randomly from an array of 10 objects of type HOUSING Use random function to generate the registration nos. to match with REGNO from the array.
Now I' trying to do this by this way
Code: #include <iostream.h> #include <conio.h> #include <stdlib.h> class housing { private: int REG_NO; char NAME[10];
[Code] .....
I am trying to pass the entire array of object in DrawNos(). but getting compilation error -
32: 'housing:rawNos(housing * *)' is not a member of 'housing' 48: Structure required on left side of . or .*
What is the problem? How can I pass the array of object in function and use it.
I wanted to input some numbers with scanf function, i can enter some numbers and if I input -1 to the scanf, the input must end. And the scanf function has limited input, the max that I can input is 40 numbers.example if enter 1 2 4 6 5 4 -1 the scanf function will ended and the result will be appear.I wanted to know how the scanf function is like that would be best for this problem, Code: scanf("%d", &n); the result if I input those number will be like