c++ problem with enum and struct [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
why doesn't this compile:
enum E { a, b}
typedef struct { int i; E e; } S;
int main(){return 0;}
I get different errors on different system.

You need a semicolon after the enum.
enum E { a, b};

There is no semicolon after the enum.

no semi colon at the end of enum

The enum needs an ; after its }

Related

C++ how to use strcpy for a 2d array in a struct [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
My compiler gives me an error when I do this:
strcpy(skin.conclusion[0], "Mel");
My struct looks like this:
struct list{
char conclusion[10][4] = {};
}skin;
What am I doing wrong or is there something else other than strcpy that I'm supposed to use.
Here is the full code that worked for me. Of course, this is C style C++ and not modern C++, there are many reasons to prefer std::string
#include <iostream>
#include <cstring>
struct list{
char conclusion[10][4] = {};
}
skin;
int main()
{
strcpy(skin.conclusion[0], "Mel");
std::cout<<skin.conclusion[0];
return 0;
}

In C++, why can int initialize a variable using new operator but double cannot? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
#include <iostream>
using namespace std;
int main()
{
int* i = new int(75);
double* d = new double(3.14159);
printf("%d\n",*i);
printf("%d\n",*d);
}
In the above code i returns a value of 75 however, d returns 1.
I tried explicitly initializing it as
*d = 3.14159
But the value is still returned as 1.
Can anyone explain what I am doing wrong here?
Use this for printing.
cout<<*i;
cout<<*d
"%f" is the (or at least one) correct format for a double if you want to use printf for printing the value of the double in C++.

error: 'listOfColors' was not declared in this scope [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm new to C++ and I don't understand why I'm getting a not declared error on this:
int main(){
string listOfColors[5] = {"red","blue","green","yellow","magenta"};
for(int i = 0;i < sizeof listofColors;i++){
cout << listofColors[i] << "\n";
}
return 0;
}
This is my first utilization of an array so far, so I may just not be declaring it correctly. I also had the array declaration before the main function beforehand.
You declared your variable as listOfColors (capital "O"), and then you use it as listofColors in your for loop. All you need to do is to capitalize the "O" when using your variable.

C++ core dump in Linux when using string as template type [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
This simple piece of code causes a core dump. I'm using gcc 4.8.2 in Linux.
template <class T>
class X
{
T c;
};
int main(int argc, char **argv)
{
X<string> *x = new X<string>[7];
delete x;
return 0;
}
I appreciate any help, I'm really confused with this. It doesn't cause a core dump when I use int instead of string.
You called new [] so you need to call delete []:
delete [] x;

What is wrong with this code in string reversal? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
In the following piece of code I get the error mentioned below. Please tell me
Why *p=t gives error here
void reverse (char *p)
{
int length=strlen (p);
int c=0, i=length/2;
char *Temp=p+length-1, t;
while (c<length)
{
t=*Temp;
*Temp=*p
*p=t;
//Gives error as illegal, right operand has type char*
//Why is the error in the above line?
c++;
Temp--;
}
}
There is a semi-colon missing:
t=*Temp;
*Temp=*p ; //--here
*p=t;