Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am trying to convert std::vector<T>::iterator to void *, but getting compiler error as wrong conversion. is there any way?
Just get the pointer to the vector element with dereference:
vector<Type>::iterator i = ...;
void* data = &*i;
Or to vector data:
void* data = vec.data();
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
if(b[s][e]!=0)
{
return b[s][e];
}
else
{
int b[s][e]=palin(str,s+1,e-1)+2;
}
I am initializing this array with a value that is returned by function palin and it is giving the following error:
[Error] array must be initialized with a brace-enclosed initializer
With
int b[s][e]=...;
you define a new array of s arrays of e integer elements.
If you want to assign a value to b[s][e] just do it:
b[s][e] = ...;
You may not use:
int b[s][e]=palin(str,s+1,e-1)+2;
That defines a new array.
Perhaps you meant to use
b[s][e]=palin(str,s+1,e-1)+2;
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I tried to write a simple function to concatenate two 2D double matrices.
double** concat(double **upmat,double **lowmat,int row,int col,int filecount)
{
double **temp=new double* [filecount*row];
for(int i=0;i<row*filecount;i++){
temp[i]=new double [col];
}
if (filecount>1)
std::copy(upmat,upmat+(filecount-1)*row*col,temp);
std::copy(lowmat,lowmat+row*col,temp+(filecount-1)*row*col);
return temp;
}
This function returns a 2D pointer. When I tried to access data from that pointer it shows invalid memory access error!!
temp, low, and high are all double** (pointer to pointer to double) , but you do std::copy as if they are double* (pointer to double) .
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am running the below code. I am getting run time error.
#include <iostream>
using namespace std;
int main() {
char *p="hello";
//p="Hi";
*p='G';
cout<<*p;
return 0;
}
if this is giving error then what is use of const char *p="hello";In this case my string should be constant not in char *p="hello"
char *p="hello";
*p='G';
You make p point to a constant, "hello". But then you try to modify what p points to. By definition, constants cannot be modified.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
XO Game C++
This code returns only "It’s a Tie !!" .. What's the error in my code?
#include <stdio.h>
int main()
{
char a1,b1,c1,a2,b2,c2,a3,b3,c3;
scanf("%c%c%c\n%c%c%c\n%c%c%c",&a1,&b1,&c1,&a2,&b2,&c2,&a3,&b3,&c3);
if(a1==b1==c1=='X'||a2==b2==c2=='X'||a3==b3==c3=='X'||a1==a2==a3=='X'
||b1==b2==b3=='X'||c1==c2==c3=='X'||a1==b2==c3=='X'||c1==b2==a3=='X'){
printf("X wins\n");
}
if(a1==b1==c1=='O'||a2==b2==c2=='O'||a3==b3==c3=='O'||a1==a2==a3=='O'
||b1==b2==b3=='O'||c1==c2==c3=='O'||a1==b2==c3=='O'||c1==b2==a3=='O'){
printf("O wins\n");
}
if(a1!=b1!=c1||a2!=b2!=c2||a3!=b3!=c3||a1!=a2!=a3
||b1!=b2!=b3||c1!=c2!=c3||a1!=b2!=c3||c1!=b2!=a3){
printf("It’s a Tie !!\n");
}
}
a1==b1==c1=='X'
This doesn't do what you think it does. It compares a1 to the boolean result of b1==c1=='X', probably giving false.
To check whether they are all equal, you need
a1=='X' && b1=='X' && c1=='X'
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am trying initialize element of array
array[m][n] == char("X");
after printing that element i'm getting the value of it equals д (Russian d); how deal with it, and I'm not even able to initialize that element without parsing const char to char.
You have to write simply as
array[m][n] = 'X';
where 'X' is a character literal.
Or if you like very much string literals then:)
array[m][n] = *"X";
or
array[m][n] = "X"[0];
EDIT: I am sorry. You have also to use the assignmnet operator (=) instead of the comparison operator (==)