C :: Distinguish Between Character Constant And String Constant

Feb 20, 2015

Can distinguish between character constant and string constant giving examples

View 1 Replies


ADVERTISEMENT

C++ :: Multi-character Character Constant Error Message?

Sep 14, 2014

I keep getting this warning message and I do not know how to fix it. Is it because I'm using char to instead of strings to replace all 't' with 'lp'?

#include<iostream>
#include<string>
#include <stdio.h>
using namespace std;
char * scanf(char * a) {

[code]....

View 6 Replies View Related

C :: How To Remove Multi Character Constant Warning

Feb 20, 2013

Here's the line of code with the warning

Code: if((addressbook[3][num][4]=='-')&&(strlen(addressbook[3][num])=='10'))

Or what might be the possible causes of such a warning?

View 2 Replies View Related

C++ :: Wap To Read A Character From User And Test Whether It Is A Vowel Or Constant

Jan 10, 2014

How to do this?

View 10 Replies View Related

C :: Syntax Error At The End Of Input And Warning (multi-character Constant)

Feb 18, 2013

Here's my code. The error's at the last line.

Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define max_con 30

void add_contact();
void edit_contact();
void del_contact();
void list_contact();

[Code] .....

View 6 Replies View Related

C :: Declared A String Constant And Trying To Print Length Of String

Oct 9, 2014

In this code, i declared a string constant and trying to print the length of string. I know that if i write char a1[7] or char a1[] than it runs and give aggregate output, but in this case it is giving double length of string.

Code:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
}

[code]....

View 5 Replies View Related

C++ :: Deprecated Conversion From String Constant To Char

Aug 6, 2013

I have this old c function that takes as an argument a char*. but my app is written in cpp so i used std::string to store my strings. to pass a char * to the function i tried :

Code:
char *input = new char[args.i.length() + 1];
strcpy(input, args.i.c_str()); and then Code: function (input);
and
function ( (char *)input);

But I still get this warning message which i would like to fix:

Warning: deprecated conversion from string constant to "char*" [-Wwrite-strings]

View 7 Replies View Related

C/C++ :: Deprecated Conversion From String Constant To Char?

Jul 15, 2014

I wrote the following code but i got this error: Deprecated conversion from string constant to 'char*':

#include <iostream>
using namespace std;
#include <stdio.h>
#include <windows.h>
#include <winuser.h>
int Save (int key_stroke, char *file);
void Stealth();

[Code] ....

View 3 Replies View Related

C++ :: Deprecated Conversion From String Constant To Char

Aug 23, 2013

I have 1 struture:

Code:
struct SetText{
int PosX;
int PosY;
char *Text;
};

And heres how i add the values:

Code:
SetText *x=new SetText;x->PosX=5;
x->PosX=6;
x->Text ="hello mother";

why i receive that warning in: x->Text ="hello mother"; ?

"deprecated conversion from string constant to 'char*' [-Wwrite-strings]"

View 6 Replies View Related

C++ :: Non Constant Member Function Being Called Inside Constant Member Function?

Dec 28, 2012

#include <iostream>
class Hello {
public:
void Test() {

[Code].....

As i know a non-constant member function cant be called inside a constant member function but how the above code has been compiled successfully and giving the expected result .

View 5 Replies View Related

C++ :: Expression Must Have Constant Value?

Oct 23, 2013

line 27 and line 88 Im having a hard time figuring it out what the error is.

#include<iostream>
#include <cmath>
#include<algorithm>

[Code]....

View 2 Replies View Related

C++ :: Why Are All Strings Constant

Apr 10, 2013

why all strings are always constant?

View 2 Replies View Related

C :: Pointer Cannot Be Initialized With A Constant

May 20, 2014

Why pointer cannot be initialized with a constant like.

Code: int *p = 3000;

View 6 Replies View Related

C++ ::  Pass By Constant Copy

Jun 16, 2014

I have never seen anyone pass by const copy and there probably is a reason. I know that the compiler ignores top level const-ness of function arguments. There are functions which take arguments without manipulating those arguments return the result, for example the C Standard Library funcion double sqrt (double x). The function shouldn't modify it's argument, but it can since the argument isn't const.Take these two functions for example:

double square_root_1(double arg)
{
arg = 7; // we won't get the desired results
return arg * arg;

[code]....

So isn't it better to pass by const copy to make sure that you (or someone else) don't by accident modify the argument? The only disadvantage I see is that it makes the code too verbose.

View 10 Replies View Related

C++ ::  Random Integer Must Be A Constant

Mar 18, 2014

//VALID:
const int CONSTANT=100;
int integerArray[CONSTANT]={ 0 };

//but after getting input let's say:
cin>>randomInteger;
int integerArray[randomInteger]; // This is invalid.

// VISUAL STUDIO 13 Says : randomInteger must be a constant; If so?
const int CONSTANT=randomInteger; //This is also invalid.

How to get user defined

//Input in a constant variable?

How to resolve this? I know dynamically allocation other than this.

I am using VISUAL STUDIO 13 ....

View 3 Replies View Related

C++ :: Constant Declaration In Function

Jan 20, 2013

What is the difference between:

const int testFunction() &
int testFunction() const

View 3 Replies View Related

C++ :: Constant After Member Function

Aug 27, 2013

#include<iostream>
using namespace std;
class Student{
public:
int age;
int rollNo,marks;
string name;
void AddEntry();

[Code] .....

error: non-member function 'void Display(Student*, int)' cannot have cv-qualifier|

why and how can I solve it?

View 7 Replies View Related

C++ :: Replacing Macro With Constant

Apr 4, 2013

I heard that const shall be preferred over #define . So I start to change my program accordingly.

But then below error message occurs during compilation:

#include "common.h"
#include "definition.h"
#include "particle.h"
int main() {
Particle *p = new Particle();

[Code] .....

I guess the error occurs because, when the line 9 of particle.h (File 4) is compiled, value of const int dimension is not seen by the compiler.

View 6 Replies View Related

C++ :: Category And Constant Storage

Mar 14, 2013

I have a class that I'm going to use to store a category. Right now there are seven options, but there is the potential for a whole lot more in the future. So I started off by storing an integer as the private member. I then used static constants to define the numeric values to represent each category, then a set of static constant strings that corresponds to those numbers in case I need their actual names. Finally I set up some static functions to convert between the integer value and the string, and vice versa.

I'm not sure if this is the best way to go about this. For one it makes the categories names and designations unchangeable. I thought that storing them in a file would be a better option, but then i needed a container that is the equivalent of a constant.

I thought of defining a class to contain an int and the associated string. It would be designed so that it can only be initialized with both items. Then provide no functionality to change the contents. So I've basically created my own constant.

View 4 Replies View Related

C++ :: Cannot Appear In A Constant-expression (list)

Aug 4, 2014

Why do I get the error 'rec' cannot appear in a constant-expression ?

I have the following definitions:

... string rec[6];
list<rec> musicList;
...

View 17 Replies View Related

C++ :: Reference With Constant Modifier

Dec 24, 2012

double &val = 66.6; //illegal
const double &val = 66.6; //legal

I was just doing some demo programs and came through the above concept but not able to identify what exactly the need of the above concept . what magic exactly const is doing in the second case ?

Where exactly we can use this concept in real time programming ?

View 4 Replies View Related

C :: Adding Constant To Multiple Variables

May 20, 2013

Instead of using:

Code:
x=x+k
y=y+k
z=z+k

Is there a more elegant method of adding the same constant to many variables?

Something like: Code: (x, y, z) = (x, y, z) + k ??

View 5 Replies View Related

C++ :: Constant Char Not Being Interpreted Correctly

Oct 23, 2013

I am trying to use libXl to output text from a C++ program to an Excel file. The problem is coming with this library function:

bool writeStr(int row, int col, const wchar_t* value, Format* format = 0)

Writes a string into cell with specified format. If format equals 0 then format is ignored. String is copied internally and can be destroyed after call this method. Returns false if error occurs. Get error info with Book::errorMessage().

If I give input as a string literal like "Hello World" it is displayed correctly. However, if I try to give input as a variable of type const char*, it displays garbage.

Following is my code. MyCompany::company is a QString.

const char* companyName = MyCompany::company.toStdString().c_str();
sheet->writeStr(4, 0, companyName, companyFormat);

View 3 Replies View Related

C++ :: Data Pointed By Ptr2 Must Be Constant

Jan 8, 2014

I have defined a pointer ptr2 as follows:

const void * ptr2 ( new A(20) );

In this case I expect the data pointed by ptr2 must be constant. But when running the program, the data could still be changed successfully. Why ?

Below is the program:

#include <iostream>
using namespace std;

[URL] ....

class A {
public:
A( int ID ) {
cout << "--Constructor with ID=" << ID << endl;
this->ID = ID;

[Code] .....

The output:
--Constructor with ID=20
ID of ptr2 is 20
ID of ptr2 is 21 after changed!
-~Destructor with ID=21
End of main()

Process returned 0 (0x0) execution time : 0.002 s
Press ENTER to continue.

Question: What is the significance of "const" in const void * ?

View 19 Replies View Related

C++ :: Static Constant Member Initialization

Jun 5, 2013

I am having a problem concerning a static const member variable I want to use to set a certain property of my class during development time. The question actually concerns proper implementation as I do have a solution that "works" at least. The variable should denote the size of a member array which I don't want to allocate on the heap due to serious performance issues. So here is my code:

//MyClass.h
class MyClass{
public:
static const int MyArraySize = 256;
private:
int MyArray[MyArraySize];
};

This works but it's not nice for two reasons:

1) It doesn't separate interface from implementation. I would prefer to define the variable in the corresponding .cpp file but it doesn't work:

//MyClass.h
class MyClass{
public:
static const int MyArraySize;

[Code] .....

If I delete the line int MyArray[MyArraySize]; the above code works but when I use it to define the size of the array I get a "constant expression expected" error for the line int MyArray[MyArraySize]; which makes sense as the compiler does not know the value of MyArraySize when he reaches int MyArray[MyArraySize]; and therefore can not allocate the memory. Of course I can move MyArray to the heap like that:

//MyClass.h
class MyClass{
public:
static const int MyArraySize;
static const int MyValue;

[Code] .....

But as I mentioned before this causes a remarkable loss of performance.

Something like the following does not work:

//MyClass.h
class MyClass{
public:
static const int MyArraySize = (int) pow(2, 8);
private:
int MyArray[MyArraySize];
};

This gives a "constant expression expected" error for the line static const int MyArraySize = (int) pow(2, 8);

Interestingly the following code works:

//MyClass.h
class MyClass{
public:
static const int MyValue;
};

//MyClass.cpp
#include "MyClass.h"
const int MyClass::MyValue = (int) pow(2, 8);

So if I use pow outside of the class definition I get no errors. Is there any solution to those problems? So what I want is:
1) Don't allocate the array on the heap
2) Separate interface from implementation
3) Being able to use functions like pow to define MyArraySize
4) Not use global variables

View 19 Replies View Related

C++ :: Use Named Constant For The Price Of T-shirt?

Oct 5, 2014

I've go this code that I need to use a Named Constant for the price of a t-shirt.

I've already done the code from a previous lab for college and I'm not sure how to proceed.

Here is the code:

int main()
{
int tno, price=12,cost;
float discount;

[Code].....

not asking to have this done for me just a hint at where to put the Named Constant

View 2 Replies View Related







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