C :: Possible To Create Char String At Compile Time?
Mar 28, 2014
I would like to have a program with a 5 mb string embedded in it kind of like this:
Code:
const char *c;
c = (const char*)"BEGIN_STRING_HERE, (5 MB of arbitrary values here)";
Is it possible to generate this string at compile time? Maybe with a macro? I'm trying to avoid a source file with a 5 mb string in it.
View 3 Replies
ADVERTISEMENT
May 13, 2013
Is there any possible way of calculating some values at compile time? I have the following code of genereting upto 2000000010 palindrome numbers.
Code:
#include <iostream>
#include <string>
#include <sstream>
#include <string.h>
#include <stdlib.h>
[Code] .....
As you see, I have taken input from the user just after calculating the whole palindromes. So cant we calculate this at compile time? because runtime of this program is extremely slow.
Another qs. I first tried to use array but It didnt allow 2*10^9 sized array. so what should I do whenever I need that size of array?
View 12 Replies
View Related
Sep 1, 2013
My question is this: Is it possible to determine where functions are stored at compile time, so that at run time you can pass the memory address as a pointer to the interrupt handler so that it can directly call the function at memory location 'X'?
The newest project I'm working on would require to either somehow capture these addresses or to find a work-around so that instead of passing the pointer to the interrupt handler, the software would then need to be able to be non-interruptable.
View 2 Replies
View Related
Jan 18, 2012
Would there be anyway for the compiler, or the language, to provide a unique ID during compilation?
I've been using UUID generators, but I've always found the approach of copy pasting from a program to code to be kind of... limiting. If I want a random number, can't the compiler guarantee this for me?
It already does the same thing for anonymous namespaces, so...
View 6 Replies
View Related
Apr 10, 2013
Consider:
Code: template<unsigned int N>
class Test
{
private:
[Code]....
I just cannot understand why (clearly, we are calling <0, 0>, not <0, 8>). If I replace "N" with 8, it works as expected (at least for the beginning of the loop). I only tested on MSVC.
View 5 Replies
View Related
Mar 6, 2013
I am working on a project, where I have to be able to exclude some code fast and dynamicly at compiletime.
I got a scheduler running and actually I just want to remove some of the tasks from it - but at compile time so that the code wont take up space in my microcontroller.
I know that I can use macros like #ifdef #endif etc. But I think that method makes the code unreadable and complicated.
How to archive such functionality a more elegant way?
View 1 Replies
View Related
Nov 19, 2013
So I made a library for a whole bunch of functions and when i compile it, it says"Unresolved external symbol_(Name of function here) referenced in function main.
View 1 Replies
View Related
Oct 22, 2013
How do I set the size of a member array via the class constructor if I know the size at compile time. I can do this with templates, see below, but this leads to code bloats, I think.
So one class declaration but objects with different array sizes.
Can't use constexpr.
Can't use STL.
Can't use new.
#include <iostream>
using namespace std;
template<int T>
class MyArray {
private:
int array[T];
public:
int getSize()
[Code] ....
View 15 Replies
View Related
Nov 5, 2014
I want to generalize my productFunction below to a template family of functions where the template merely changes the * to + or whatever else operator I wish to use.
#include <iostream>
#include <functional>
#define show(variable) std::cout << #variable << " = " << variable << std::endl;
template <typename, typename...> struct ProductFunction;
template <typename RETURN_TYPE, typename FIRST, typename... REST>
struct ProductFunction<RETURN_TYPE, FIRST, REST...> : ProductFunction<RETURN_TYPE, REST...> {
const FIRST function;
using Base = ProductFunction<RETURN_TYPE, REST...>;
[code].....
How can I turn a template parameter into various operators? (apart from using switch statements that will reduce the performance and make the code really ugly) What kind of metatemplating method converts a compile-time constant to an operator?
View 3 Replies
View Related
Feb 4, 2014
I am trying to build a VC++ project in Visual Studio 2010. [URL] ....
This project has a dependency on openssl libraries. How can I successfully build this project? How to add third party libs/dlls in a project.
View 1 Replies
View Related
Mar 6, 2015
Code:
typedef struct token
{
int tokenType; // what token is that
int tokenCode; // the code of a function if applicable
char *tokenString; // Source token
double tokenValue; // if token is a number
[Code] .....
I got several warnings and erros, is it possible to declare a table like that ? What's the correct way to declare it ?
View 4 Replies
View Related
Aug 2, 2013
I am trying to convert char to time and I found the following code. But it gives me a -1 on "converted" instead of time.
#include <stdio.h>
#include <time.h>
#include <iostream>
using namespace std;
[Code].....
View 7 Replies
View Related
Dec 16, 2013
I am trying to create a program that calculates fraction of time remaining when a student leaves during the middle of the semester. I have to use function files here. I am having trouble with the division in function long double tuitionfrac(int, int, int). No matter what numbers are entered, fractime gives an output of 0. I don't understand that.
long double tuitionfrac(int opening, int leaving, int semend)
{
int lefttime = semend - leaving;
cout << "Left time " << lefttime << endl; //for error checking
int tottime = semend - opening + 1;
cout << "Total time " << tottime << endl;
long double fractime = lefttime/tottime;
cout << "fractional time " << fractime << endl; //always returns as 0.
return fractime;
}
View 4 Replies
View Related
Mar 13, 2014
I am trying to create two classes: a Date class and a Time class. The Date class has to have three private data members: day, month and year. The Time class should have two private data members:hour and minute. Each class should have two member functions: a constructor and display. I am lost and my code won't run ....
class Date {
private:
int month, day, year;
public:
Date(int m, int d, int y){
month = m;
day = d;
year = y;
[code]....
View 2 Replies
View Related
Jan 14, 2015
I am trying to use to save the current date and time into a char array using this code:
char current_time(char *date){
time_t result = time(NULL);
date = ctime(&result);
return *date;
}
main{
[Code]...
now when I output the date char array into a txt file I only get gibberish.
View 6 Replies
View Related
Jan 26, 2012
I need to create a function that performs the addition of x days at a time, taking two integer values, the first being a date (yyyymmdd format) and a number of days to add / subtract that date.
How can I perform validation if the entire amount received is a valid date and how can I add x days of that date?
View 8 Replies
View Related
Aug 8, 2014
I'm trying to create a program to calculate the flight time and fuel burn of an airplane. However when I repeated the whole calculation, it did not show any data or result like the previous calculation. In addition, the "If" statement that I used to test the "fuelRemain" doesn't work properly. I can't figure out why.
Here are the outputs [URL]
#include <iostream>
#include <fstream>
#include <string>
[Code].....
View 2 Replies
View Related
Mar 27, 2013
I want to create a map contaning a regex as key and a char* as an attribute , like:-
map<regex, char*> res;
res["[[:alnum:]]"] = "alphanumeric text";
but the following error is generated:-
vector<pair<regex,string>>res;
res.push_back(make_pair("[[:alnum:]]","alphanumeric"));
but the error generated is:-
no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=std::pair<std::regex, std::string>, _Alloc=std::allocator<std::pair<std::regex, std::string>>]" matches the argument list
argument types are: (std::pair<const char *, const char *>)
object type is: std::vector<std::pair<std::regex, std::string>, std::allocator<std::pair<std::regex, std::string>>>
View 13 Replies
View Related
Dec 20, 2014
I have the codes for such a problem where, to create a program that counts how many times the second string appears on the first string. Yes it counts if you put 1 letter only, but if you put 2, it is an error. As an example. If the first string is Harry Partear, and the second string is ar, it must count as 3. Here's the code:
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
[Code] ....
View 6 Replies
View Related
Apr 20, 2013
I'm trying to "tokenize" a string using std::string functions, but I stored the text in a char array. When I try to convert it to a string, the string has the first character right but the rest is garbage.
// Get value from ListBox.
char selectedValue[256];
memset(selectedValue, NULL, 256);
SendMessage(GetDlgItem(hWnd, IDC_LB_CURRENTSCRIPT), LB_GETTEXT, selectedIndex, (LPARAM)selectedValue);
// Convert to string.
string val(selectedValue);
[Code] ....
View 3 Replies
View Related
Feb 5, 2013
A string class that finds a char in the string?
View 1 Replies
View Related
Aug 25, 2013
How do I use string and atoi at the same time?
string scroes;
char input[SIZE];
cout<<" Enter your score" << endl;
cin.getline (input, SIZE);
scores = atoi (input);
View 1 Replies
View Related
Aug 28, 2014
This is what I have:
#include <ctime>
#include <string>
using namespace std;
void date_and_time(string &date, string &time){
time_t current_time;
[Code] ......
Is there a way to make sure that the strings would not contain trailing spaces?
View 1 Replies
View Related
Feb 12, 2014
Is there a variable that can hold string and int in the same time?
If not, what can I do if I want to input data with string and int like a password for an example.
View 3 Replies
View Related
Jun 5, 2013
I have a vector<string> of times that I want to convert to vector<double>. The time string is in the form 00:00.000. Is there a STL or something like it algorithm or function to do this, otherwise what would be the best way to do this with a function.
View 3 Replies
View Related
May 10, 2013
may i know how do i read a string 2 characters at a time?
lets say i have a for loop like this
for(int i=0;i<stringLen;i++)
{
for(int j=0;j<???;j++)
{
//insert code
}
}
what i want to do is i want to read a string 2 characters at a time and store them into a vector.
View 3 Replies
View Related