C++ :: Create User Define Literal?

Jul 14, 2014

In C++ there are a number of primitives that are not defined in terms of other types. By this I'm thinking

int a = 1;
char b = 'M';
float c = 3.45f;
short d = 0xC3A3;

Is it possible to define your own literal? What I would like to do is have a hex literal for a data type where n = sizeof(data_type). If this type were a big integer, then I would want something like:

BigInt e = 0x13CA9B0C98D983E912DA0B0A9F87E0;

My goal is to assign a value from one contingous chunk of bytes and to not do it with a string.

View 1 Replies


ADVERTISEMENT

C++ :: Create Class Vector As Template And Define Operations On Vector?

May 13, 2013

I need to create a class vector as a template and define operations on vectors.

And this is what I made.

#include<iostream>
using namespace std;
template<class T>

[Code].....

View 2 Replies View Related

C :: How To Create Graphical User Interface

Feb 25, 2013

How can i create a graphical user interface using c

View 10 Replies View Related

C :: Create File From User Input

Jun 27, 2013

I want to create three files whose names are same but extensions are different. I have to take the name from user. I tried following code but it didn't worked ...

Code:

printf("Name of the file:"); scanf("%s",name);
printf("Format of Input file:");
scanf("%s",ext);
f1=fopen(name.ext,"r");
f2=fopen(name.dat,"w");
f3=fopen(name.src,"w");
f4=fopen(name.RMH,"w");

View 1 Replies View Related

C/C++ :: Allow User To Create A New Class Instance?

Dec 4, 2014

I am creating a program that allows a user to create multiple 'sequences' and multiple 'filters' and then apply a filter to a sequence.

Each sequence and filter is an array of values.

How do I go about allowing the user to create a 'new' sequence and then store the location so I can access it again later? Once they have created a new sequence they can go on to create another sequence and ten maybe a filter and then another sequence etc etc .. and then they can select sequence 1 and edit the values if they so wish.

They would be asked how many sample values for the sequence, and then I would create a sequence with that many values and an id (1,2,3,4...). They could then enter this id to view/edit the sequence.

The entering/editing values part I am fine with. I just don't know how to allow them to create multiple new instances of a class without using an array so something like..

sequenceClassName somearray[10];
int i;
*create a new array*
somearray[i].create_class(how_many_samples)
i++ //so next sequence they create is 2,3,4.. etc

- this then calls the member function that creates an array using 'sample_values = new float[how_many_samples]' and the user can input their data and edit it whenever by entering the id which will correspond to the somearray[i].

However that approach only allows them to enter a maximum of 11 sequences. It all depends on how big I make that initial array and it just seems like the wrong way to do it.

( how to interact with them, just how to create multiple classes and recall them later to access the data!)

View 2 Replies View Related

C :: Program That Allows A User To List All Create New Items

Dec 30, 2013

i want to create a program that allows a user to list all create new items, list those items, delete an item, modify an item, search for an item how can i do that This is my work so far

Code:

#include <stdio.h>
#include <string.h>
struct listofitems
char itemName [50];
float itemPrice = 0;
}

[code]...

View 1 Replies View Related

C++ :: Program To Create A Dialog Box And Shows It To User

Dec 20, 2014

I want to make a programs which creates a dialog box and shows it to the user. The dialog box should not be pre-loaded, here's an example:

cout << "Button a"
cin >> a
cout << "Button b"
cin >> b
cout << "Button c"
cin >> c

[Code] .....

Each button should be under the other. How can I do this in a C++ project?

View 1 Replies View Related

C++ :: Program To Create Integers As User Requests?

Nov 19, 2013

I know it would be easier to create an int array, but I want the program to create integers as the user requests. For example, if the user enters 4, the program creates 4 integers with the names input. Each integer is better as an individual integer, not an element in an array.I'm not sure if this is a possibility with C++.

View 3 Replies View Related

C++ :: Create Fibonacci Sequence With Some User Inputs

Aug 26, 2013

I'm trying to make a fibonacci sequence with some user inputs. I'm using arrays for this, the user inputs are for the Nth term and the starting number (as in the number in front of 0).

My problem is that when the program runs it's an infinite loop which constantly prints the starting number. Which, I think, means that my WHILE loop isn't coming to an end and my 'count' variable isn't increasing.

#include <iostream>
using namespace std;
int main() {
int start;
int term;
cout << "Input a starting number for the sequence: ";
cin >> start;
cout << "
Enter the Nth term for the sequence to reach: ";

[code].....

View 4 Replies View Related

C++ :: Create A Grading Program That The User Inputs A Name?

Feb 17, 2013

I want to create a grading program that the user inputs a name and then on that value (name) there is a vector of doubles to represent his/her mark and then calculates an average how would I go about doing this?

View 1 Replies View Related

C++ :: Create A Program That Will Prompt The User For Input?

Dec 28, 2014

I need to create a program that will prompt the user for an input, then it will save their input to a file and then it will prompt the user to input "Open" and then the file containing their first input, will open up and show their input.

View 19 Replies View Related

C# :: How To Create A Window Where User Can Open A File

Dec 15, 2014

I am using

string text = System.IO.File.ReadAllText(@"C:datainput.txt");

to open a file and save it content to "text"

How can I instead create new window where user will select the .txt file he wants to read like many applications do

This is a WPF application

View 10 Replies View Related

C :: Create A Program That Prints A Number Of Dots Specified By User

Oct 8, 2013

I'm trying to create a program that prints a number of dots specified by the user, there 4 options to do any loop type or to exit the menu. i'm having problems making it so that after you enter a value and it displays the specified number of dots it clears the results. Also we have to make it so that if a negative integer is entered it still prints out the appropriate amount of dots ie: user puts -9 it prints 9 dots, i know you use the abs() function but it doesn't seem to be working for me. I'm assuming my problem with the abs function is i'm not using it correctly. Use case 1 as the example for the rest because I'm trying to implement everything on one case at a time

Code:

int main() {
//initialization statements
int Num1 = 0;
char dot = '.';

[code]....

View 7 Replies View Related

C++ :: Create A Program That Will Let User Input Amount In Form?

Jan 4, 2014

Figure this out using [TURBO C]

Create a program that will let the user input an amount in the form (367). The Program should determine the no. of coins for each dominations : 50,25,10,5,1. (using Turbo C)

View 7 Replies View Related

C++ :: Create Program That Has User Input 5 Digit Number?

Mar 9, 2013

Im trying to create a program that has the user input a 5 digit number. If it's between 10000 & 99999, it will do one thing..(just saying 'yes' for now. Outside those numbers will prompt the user to input again. However, if the user inputs the exact digits 76087, it should display 'term'.

This current code is displaying 'term' whenever the user inputs the 5 digits.

Code:

#include <iostream>
using namespace std;
int main() {
int pin;
cout << "Welcome to Movie Food
Enter your 5-digit pin code: " ;

[code]....

View 14 Replies View Related

Visual C++ :: Create A File That Ask The User To Enter His Info

Nov 9, 2014

What I want to do is create a file that will ask the user to enter his info,n then store it in a text file The screen will ask the user if he wants to update his info. if he says yes then the screen will be cleared and the old info will be printed on the screen. The user will enter his new info that will be stored in a new file. My problem is that once the user finishes entering his input the program just closes D: and the rest of the program won't run.

Code:

int main()
{
string ans;
ofstream Xfile("original.txt");
cout <<"Enter your name and address please"<<endl;
cout<<"Press Ctrl+Z+Enter when you are done"<<endl;
string name_and_street;

[Code]...

View 3 Replies View Related

C# :: Instantiation Of Literal Strings?

Apr 5, 2012

I have a huge xml file from which the key and value attributes are selected among other things.

Code:
foreach (
XmlNode node in
configProductCode.SelectNodes("/configuration/appSettings/add"))
{
ConfigProductCode cpc = new ConfigProductCode();

XmlAttribute keyAttr = node.Attributes["key"];
XmlAttribute valAttr = node.Attributes["value"];
// etc
}

How does C# handle the instantiation of literal strings? does it make a new object with allocating heap memory on every iteration or just once?

View 2 Replies View Related

C++ :: String Literal With Constexpr

May 28, 2013

I have a binary identifier which I tried to make a constexpr since all of its calculations would never occur during runtime (this is true for literal identifiers, right?). Since constant expressions can only have one instruction, I tried to cheat a little and returned an immediate call to a lambda function. This failed miserably however. I tried making a constexpr function pointer and called that from _binary down below, but the compiler still felt that it wasn't a constexpr. Why is this? And is there a way to make a function like _b below constexpr?

#include <iostream>
#include <cstddef>
using std::cout;
using std::endl;
long unsigned //Original
operator"" _b(const char* const literal, size_t lsize){

[Code] .....

View 4 Replies View Related

C :: Assigning A Pointer To A String Literal

Sep 13, 2013

In another forum, this example code fragment was stated as being an example of undefined behavior. My understanding is that a literal string exists from program start to program termination, so I don't see the issue, even though the literal string is probably in a different part of memory.

Code: /* ... */
const char *pstr = "example";
/* or even */
char *pstr = "example";
/* as long as no attempt is made to modify the data pointed to by pstr, */
/* unless pstr is later changed to point to a stack or heap based string */

View 11 Replies View Related

C :: Free A String Literal From Memory?

Jan 8, 2014

This compiles o.k.:

Code:

int main(void){
char *a;
a = (char*) malloc (100*sizeof(char));

[Code]....

I get an error saying "pointer being freed was not allocated". This happens for free(a), free(*a), free(&a), free(&*a).

So if I no longer need "1234567"... how do I get rid of this memory element?

View 7 Replies View Related

C++ :: Overloading Operator + For Literal Strings?

Sep 8, 2013

i have 1 nice write() function:

void write() {
cout <<"";
}
template <typename A, typename ...B>
void write(A argHead, B... argTail) {
cout << argHead;
write(argTail...);
}

these function works. but if i concat literal strings with '+', i must use '(string)'. so i'm trying overload the operator + for concat literal strings, but without sucess:(

string operator + ( char *value1) {
string value2;
value2=(string) value2+value1;
return value2;
}

(these functions are inside of my Console class)

View 2 Replies View Related

C++ :: Use Of A Backspace Character In A String Literal

Apr 19, 2014

In the following char array, notice the use of a backspace character in a string literal: ''.

char text1[50] = "aHello,
World! Mistakee was "Extra 'e'"!
";

What exactly does a backspace character do here? When the compiler evaluates this line, does it actually delete the previous character, like when you press the backspace button on the keyboard?

View 1 Replies View Related

C/C++ :: Difference Between Literal And Symbolic Constants?

Jun 29, 2014

"A constant, like a variable, is a memory location where a value can be stored. Unlike variables, constants never change in value. You must initialize a constant when it is created. C++ has two types of constants: literal and symbolic.

A literal constant is a value typed directly into your program wherever it is needed. For example, consider the following statement:

long width = 5

This statement assigns the integer variable width the value 5. The 5 in the statement is a literal constant. You can't assign a value to 5, and its value can't be changed.

The values true and false, which are stored in bool variables, also are literal constants.

A symbolic constant is a constant represented by a name, just like a variable. The const keyword precedes the type, name, and initialization. Here's a statement that sets the point reward for killing a zombie:

const int KILL_BONUS = 5000;

Whenever a zombie is dispatched, the player's score is increased by the reward:

playerScore = playerScore + KILL_BONUS;

If you decide later to increase the reward to 10,000 points, you can change the constant KILL_BONUS and it will be reflected throughout the program. If you were to use the literal constant 5000 instead, it would be more difficult to find all the places it is used and change the value. This reduces the potential for error."

what's the difference? Here is a program to demonstrate what I'm having trouble conceptualizing.

#include <iostream>
using namespace std;
int main() {
int width = 10, length = 10;
int area = width * length;
cout << "Width: " << width << endl;
cout << "Length: " << length << endl;
cout << "Area: " << area << endl;
return 0;
}

Now, why would it be harder to go in and changed a regularly defined integer than one defined with the 'const' keyword proceeding it? For example, the width and length variables. My confusion comes from the point that they seem to both simply be variables with a value assigned to them. I feel as if the process of having to change a literal constant's value is synonymous to the process of having to change a symbolic constant's.

View 3 Replies View Related

C/C++ :: Pointer-to-char To String Literal?

Oct 6, 2014

how string literal that works with the cin object?

char * str = "This is a string constant";

Is the str stored the address of the first character of the string literal?

But some books just state that the pointer-to-char (char pointer) stores the address of the string literal". So just wonder how it is.

When it is used with cout, cout just treats it like a string and instead of printing the address, it just prints out all characters one by one until it reaches the terminated null character.

If this is the case, then I am just wondering how cin works with it? with a statement like this cin >> str; ?

Does the computer allocate enough memory for it? and then cin stores the first character into the first address and then advances to the next address and stores the next character?

View 1 Replies View Related

C++ :: Create A Program Which Prompts For User Input Of Current And Birth Date

Sep 27, 2014

I have an assignment in which i must create a program which prompts for user input of current and birth date, which will compare said dates and output if its your birthday or not. I've completed a large portion of it, but cannot figure out how to get the user input of month as an integer such a 2 into February.

#include <iostream>
using namespace std;
class DayOfYear {
public:
void input();

[code]....

View 1 Replies View Related

C/C++ :: Create A Program That Prints A Certain Number Of Asterisks Based On User Input

Apr 12, 2015

I need to create a program that prints a certain number of asterisks based on user input. The user inputs 5 and I want my program to output "*****". How would I do this in C? I've tried printf("%#**", myvariable) but this does not work it only prints "*".

View 1 Replies View Related







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