C++ :: How To Create Unique Types Like That Of Boost Files

Apr 5, 2013

I've been studying metaprogramming and reviewing many documents and code regarding boost files. What I've been trying to understand and accomplish is creating various types using typedef, template and struct, similar to that of the boost files themselves, to create comparators. Ultimately, I want to be able to create a type that has sub-properties which can be further compared and classified.

Informal example:

create type
typedef int coordinate[3];
create standards - "typeless prototypes"
static const coordinate _x = {1,0,0};
static const coordinate _y = {0,1,0};
static const coordinate _z = {0,0,1};

We "now have" three variables under one unique type. Now I want to wrap this further to work with other types (int, float, etc.).

create special cases

template<class ty, coordinate c> struct coord_type;
typedef coord_type<int,x> x_i;
typedef coord_type<float,x> x_f;
typedef coord_type<int,y> y_i;
typedef coord_type<float,y> y_f;
typedef coord_type<int,z> z_i;
typedef coord_type<float,z> z_f;

declare more standards

const x_i i_i;
const x_f i_f;
const y_i j_i;
const y_f j_f;
const z_i k_i;
const z_f k_f;

Where other variables can be represented based off this i,j,k standard and written in a more direct vector form.

And so on...

What I essentially would like to do is have x,y,z variables act as standards for an i,j,k system that classify arbitrary variables of the coordinate type: Is the arbitrary variable i, j, or k? Is it defined as an int or float type?

Where arguments such as sum_y = var1 + var2; are valid, provided:
sum_y is outputted as 6j, and var1 and var2 are 2j and 4j, respectively.

View 9 Replies


ADVERTISEMENT

C++ :: Listing Files With Boost Filesystem

Jun 7, 2013

I have the following code which is based of the tut3.cpp example at: [URL] ....

However, I'm not entirely sure how to retrieve the full file path which I'd like to use to get the file size. So essentially the aim is to go through a directory and list all the file sizes.

Code:
if (exists(p)) {
if (is_directory(p)) {
cout << p << " is a directory containing:
";
copy(directory_iterator(p), directory_iterator(), // directory_iterator::value_type

[Code] ....

View 1 Replies View Related

C++ :: List Of Functions That Can Create A Unique ID

Nov 4, 2014

I'm working on a list of functions that can create a unique ID for a computer. Here's what i have so far:

GetAdapterInfo();
RegOpenKeyEx();
GetVolumeInformation():
CoCreateGUID();

Are there any other functions that do this?

View 1 Replies View Related

C++ :: How To Create Tree Data Structure With Boost

Oct 1, 2013

There seems to be lacking support for tree data structure. You have to implement it yourself?

View 2 Replies View Related

C++ :: Naming Files And Making File Types?

May 12, 2013

How to deal with files and I wanted to make a way for the user to make his own file name and then I want it to be a .txt file, so I take the fileName variable after the user has created a name for it then add ".txt" for the file type then convert the string to a constant char for the open method.

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int main() {

ofstream fileObject; // ofstream object to read/write to and from file

[Code] ....

View 2 Replies View Related

C++ :: Parse Executable Files - Registering Types To Be Used At Runtime

Jul 30, 2014

I'm writing a program that needs to parse executable files. I've got an "executable" base-class, and currently an "elf" class which inherits from it for parsing ELF files, and I will add more parsers (COM, MZ, PE, a.out, MACH-O, whatever) later on.

I want the program to automatically detect which kind of executable it's loading at runtime. It should be easy because every executable format I'm aware of/plan to support starts with a magic number. But because I can't have the parsers not check the file type (what if I re-use the code?), and I don't want to check each file twice (not just for performance, but also because only the ELF parser should know that ELF files start with "x7fELF", etc.) so I've come up with a pretty lazy solution: just try to parse the file with each known parser and have them throw an exception ("exe_type_error") if they can't parse it. If that exception gets thrown, try the next parser; if not, stop.

The remaining problem is how, at runtime, my program will know what parsers are available. I don't want to hard-code it in the main function; instead, I'd like the parsers to "register" themselves as available. That way, if I decide to go down the route of adding new parsers via dynamic linking, I will only have to add an API for dynamic libraries to register their parser, without recompiling any of the main program's code. I also want to do the same thing for another key part of the program (it's a static executable optimizer; it will run a series of "tests" (e.g. "is xor eax, eax faster than mov eax, 0 on this machine?") and optimizations ("if yes, change all mov eax, 0 to xor eax, eax") and I want to load those at runtime too).

View 11 Replies View Related

C/C++ :: Create User Defined Dynamic Array For Player Scores - Missing Pointer Types Error

Jan 18, 2015

I'm completely new to pointers and have a homework assignment due where I'm supposed to create a user defined dynamic array for player scores. The only errors I'm experiencing is a C2109: subscript requires pointer type and only on the lines that use the int *score; variable (57, 62, 64, 69, 71, and 82). I've already tried adding = nullptr to the variable and that didn't work.

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
void players(string[], int[], int);
void average(int[], int);

[Code] ....

View 3 Replies View Related

C :: Parameter Names Without Types And Conflicting Types In Fgets

Jan 22, 2014

I have this

Code:

#include<stdio.h>
#include<ctype.h>
#include<string.h>

int check_up(char string[]);
int check_low(char string[]);
void to_up(char string[]);
void to_low(char string[]);

[Code] .....

When I compile this I have the following problems: warning: data definition has no type or storage class [enabled by default] in 'to_up(word)'conflicting types in 'to_up' function and to_low function warning: data definition has no type or storage class [enabled by default] into_up function error: unknown type name "word" in line 'printf("All uppercase %s. ", word):;'warning: parameter names (without types) in function declaration [enabled by default] in 'to_up(word)'and 'to_low(word)' 'note: previous declaration of "to_up" was here in function declaration of to_up function

View 7 Replies View Related

C++ :: Make Program To Create New Text Files?

Jul 9, 2013

I want to make a program that can know the current time and create a new .txt file.For example if its Monday to day then when its Tuesday it crates a new txt file called Tuesday.I really don't know how to go about this.I know i will need to use the time.h library.

View 4 Replies View Related

Visual C++ :: Recursion - Create Directories And Upload Files?

Jul 21, 2013

The code below is suppose to create directories and upload files, but it is not working. What can I do to make the code work?

Code:
void CRECURSIONDlg::Recursion(CString sPath) {
hInternet = InternetOpen(TEXT("BEAR FTP"),
INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

// Make sure there are no errors
hIConnect = InternetConnect(hInternet,"192.168.1.4", 211,
"******", "*****", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);

[Code] ....

View 6 Replies View Related

C++ :: How To Create True False And Multiple Choice Questions Using Text Files

Jan 7, 2015

So im trying to create a quiz using c++ that incorporates three different types of questions. These are the standard one answer question, true false questions and multiple choice questions.

How to create the true false and multiple choice questions?

One way that i came up with looks like this

Question A answer1 B answer2;

View 2 Replies View Related

C++ :: How To Boost Up Execution

Feb 23, 2013

I wrote a program to run long simulations, in one cpu core computation. During the run, I checked the cpu occupation was always around 85%.

Since my simulation took time to run. How can I boost it up to make my cpu run at 100%? Is that because my RAM is not fast enough?

info about my laptop: cpu frequency: up to 3.2 GHz. RAM frequency: 1333 MHz.

View 2 Replies View Related

C :: Unique Word Counter

Jun 18, 2013

I am trying to make a program which reads a text file, separates the strings into words, then finally saving and counting each different word.

When I comment out the code where it is supposed to search for the same word in the table, the program doesn't work.Am I doing something wrong with strcmp or the loop? The 'break' just exits out of that 'for' loop right?

Code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define WORD_MAX 500
#define LIST_MAX 500
int main(){
int i, j, find;

[Code]...

View 6 Replies View Related

C :: Inserting Unique IDs In Structure

Aug 11, 2014

I've used qsort to extract the unique student IDs by jumping every four because there's 80 rows of data and twenty students.

I want to make sure it's all working and there's something very strange going on. If you look at my code, when it comes to initialising the structure with the unique student IDs it will happily print them after each one has been initialised inside the for loop (which suggests to me it's obviously done it) but, however, when I want to print them again outside the for loop in another for loop as a "double-check" it goes horribly wrong, presumably they're not in there at all? If you traverse the code to the bottom you'll see my comments.

Now in my for loop, j is going to be incremented 20 times which will correspond to the #define STUDENTS 20. So imagine the array of structure db[j] , the first loop will set i and j both to zero, retrieve the first unique ID and store it in the structure. Then i is incremented by four to acces the next unique ID and then j is incremented by 1 to insert this new ID in the structure.

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

[Code]....

View 3 Replies View Related

C++ :: Function To Use Unique For Class?

Dec 6, 2013

if i can use a function to use unique for my class and also i want to count how much each of them is duplicated. i mean i have (420,250,420,66,444,777,250) in my list i would like to know that 420 is duplicated 2 times and also 250. Is there a way to get this result ?

list<Patient *> ListePatient
ListePatient.unique(g_nas()); // nas is a attribute of the class patient

View 2 Replies View Related

C++ :: Passing A Reference Of Arg (boost Lib)

Dec 19, 2013

I have in my main(), a function that creates my arg object using boost/program_options.hpp i want to pass this object to another function using templates like this:

Code:
template <typename Targ>
void Count(Targ & arg){
MyObj<string> QueryTab(arg["input-file"].as<string>()); //line number is 352
...
}

However I get an error:

Code:
../include/Filter.hpp: In member function ‘void Count(Targ&)’:
../include/Filter.hpp:352:40: error: expected primary-expression before ‘>’ token
../include/Filter.hpp:352:42: error: expected primary-expression before ‘)’ token
... obviously it does not recognize my intention, what did I do wrong?

View 2 Replies View Related

C++ :: How To Get Boost Libraries To Work With QT IDE

Mar 5, 2013

I have an issue getting boost libraries to work with QT IDE. Here are relevant lines from my .pro file...

INCLUDEPATH += c:/users/bob/desktop/boost_1_53_0/
LIBS += -LC:c:/users/bob/desktop/boost_1_53_0/stage/lib64

After adding #include <boost/filesystem.hpp> I get error...

C:UsersobDesktopqtpuntitled5mainwindow.cpp:3: error: C1083: Cannot open include file: 'boost/filesystem.hpp': No such file or directory

The IDE does not highlight the line. The error only appears on compilation.

View 2 Replies View Related

C++ :: Boost Filesystem Exception

Mar 12, 2014

I have one problem deleting a file with boost. The file is opened in another application and cannot be deleted. I am supposed to received an exception error but I don't get it.

Here is my piece of code, very simple:

bool delete_file(const string &path) {
boost::filesystem::path bpath(path);
try {
if (boost::filesystem::remove(bath)) return true;

[Code] ....

I have put a breakpoint inside the catch part but it does not come to this point. Instead, the the output window of visual studio, I got these lines:

First-chance exception at 0x00007FFD2E575A88 in site_server.exe: Microsoft C++ exception: boost::filesystem::filesystem_error at memory location 0x00000070F8E3E920.
Unhandled exception at at 0x00007FFD2E575A88 in site_server.exe: Microsoft C++ exception: boost::filesystem::filesystem_error at memory location 0x00000070F8E3E920.

How to manage this situation?

View 1 Replies View Related

Visual C++ :: Boost Is Not A Namespace

Nov 29, 2013

exportmain.cpp

Code:
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
// Create an empty property tree object
using boost::property_tree::ptree;
#include "kwxport.h"
#include "resource.h"

[Code] ....

How can I make boost:roperty_tree:tree get recognized by the compiler?

View 2 Replies View Related

Visual C++ :: How To Add Boost Libraries

Oct 1, 2013

i have written an algorithm in VC++ 2010 express edition. i have used the following header files

#include<iostream>
#include<string>
#include<sstream>
#include<ctime>
#include<cassert>
#include<fstream>
#include<vector>

[Code]...

the algorithm worked fine in vc 2010 express edition....

the following header files are not working in vc5

#include<regex>
#include<tuple>
#include<numeric>
#include<unordered_set>
#include "clip.h"

Looks like some of hte boost libraries have to added with vc5.. If any one knows how to add boost libraries with vc5.

showing lot of errors in vc5... not able to run the algorithm in vc5. Our company has only vc5.... the algorithm has to be implemented in vc 2010....

View 2 Replies View Related

C++ :: How To Read Tag Name Of Boost Ptree

Mar 23, 2014

[URL] ....

I wonder how tag reading can be achieved? If say I have a file like

<name>
<firstname>John</firstname>
<surname>Robinson</surname>
</name>

I'd like to read "firstname" or "surname" instead of John or Robinson ....

View 4 Replies View Related

C :: Finding Unique Strings Within A File?

Aug 10, 2014

I have been trying to write this program that reads a file of courses and then stores only the unique courses in an array of strings.

for some reason it crashes while reading the 2nd line.

printf within the function are just for me trying to trace the problem.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char** uniqueCourses(FILE *fp, int *wordCount);
int main()

[code].....

View 5 Replies View Related

C++ :: Find All Unique Triplet In Given Array With Sum Zero

Feb 26, 2015

I got all unique triplet from below code but I want to reduce its time complexity. It consist three for loop. So my question is, Is it possible to do in minimum loop that it decrease its time complexity. code will be execute in minimum time.

#include <cstdlib>
#include<iostream>
using namespace std;
void Triplet(int[], int, int);
void Triplet(int array[], int n, int sum) {

[Code] .....

View 7 Replies View Related

C++ :: How To Count Unique Words In A Program

Sep 16, 2013

Write a C++ program that reads lines of text from a file using the ifstream getline() method, tokenizes the lines into words ("tokens") using strtok(), and keeps statistics on the data in the file. Your input and output file names will be supplied to your program on the command line, which you will access using argc and argv[].

You need to count the total number of words, the number of unique words, the count of each individual word, and the number of lines. Also, remember and print the longest and shortest words in the file. If there is a tie for longest or shortest word, you may resolve the tie in any consistent manner (e.g., use either the first one or the last one found, but use the same method for both longest and shortest).

You may assume the lines comprise words (contiguous lower-case letters [a-z]) separated by spaces, terminated with a period. You may ignore the possibility of other punctuation marks, including possessives or contractions, like in "Jim's house". Lines before the last one in the file will have a newline (' ') after the period. In your data files, omit the ' ' on the last line. You may assume that the lines will be no longer than 100 characters, the individual words will be no longer than 15 letters and there will be no more than 100 unique words in the file.

Read the lines from the input file, and echo-print them to the output file. After reaching end-of-file on the input file (or reading a line of length zero, which you should treat as the end of the input data), print the words with their occurrence counts, one word/count pair per line, and the collected statistics to the output file. You will also need to create other test files of your own. Also, your program must work correctly with an EMPTY input file – which has NO statistics.

Test file looks like this (exactly 4 lines, with NO NEWLINE on the last line):

the quick brown fox jumps over the lazy dog.
now is the time for all good men to come to the aid of their party.
all i want for christmas is my two front teeth.
the quick brown fox jumps over a lazy dog.

Copy and paste this into a small file for one of your tests.

Hints: Use a 2-dimensional array of char, 100 rows by 16 columns (why not 15?), to hold the unique words, and a 1-dimensional array of ints with 100 elements to hold the associated counts. For each word, scan through the occupied lines in the array for a match (use strcmp()), and if you find a match, increment the associated count, otherwise (you got past the last word), add the word to the table and set its count to 1.

The separate longest word and the shortest word need to be saved off in their own C-strings. (Why can't you just keep a pointer to them in the tokenized data?)

Remember – put NO NEWLINE at the end of the last line, or your test for end-of-file might not work correctly. (This may cause the program to read a zero-length line before seeing end-of-file.)

Here is my solution:

#include<iostream>
#include<iomanip>
#include<fstream>
using std::cout;
using std::ifstream;
using std::ofstream;
using std::endl;
using std::cin;
using std::getline;
void totalwordCount(ifstream&, ofstream&);

[Code] .....

Question: In the uniquewordCount() function, I am having trouble counting the total number of unique words and counting the number of occurrences of each word. In the shortestWord() and longestWord() function, I am having trouble printing the longest and shortest word in the file. In the countLines() function, I think I got that function correct, but it is not printing the total number of lines. Is there anything that I need to fix in those functions?

View 2 Replies View Related

C++ :: Seed Unique Random Numbers?

Jan 13, 2014

Is there a way of using a rand-function in a way that it seeds the same random numbers every time the function is used? I'm looking fomr something like:

int * randfunction(hash maybe){
//Fancy code...
return // quasi random numbers, same each time function is used.
}

I'm testing an algorithm where I need a set of unique random numbers. So far I've only used hard coded numbers on small scale test runs. I'd like to do the up scaling, but haven't really figured out how to seed random numbers like I need to.

View 4 Replies View Related

C/C++ :: Container To Store Objects Under (unique) ID

Jun 14, 2014

I searching for a container/collection, that can access very fast to objects with the associated id.

Arrays are a bad idea, because it can be that I must store objects with a big id for example 9394034, so the array would be to big.

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved