invalid conversion from int to int c++ [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to make something in WinAPI but I get big loads of errors, corrected most of them but i cant find solution to that one:
for (LPINT i = 1; i <= ilosc; i++)
The compiler shows that error is is the "1".
I would post the entire code but its so unorganized that it would be hard to find this line in it the loop for declares its own variable so i think that I'm using the wrong type of variable (no clue what would be correct)
I changed the names of every variable I have to LP* and it solved almost all of my problems except this one.
Also if someone is well oriented in the topic of WinAPI could you teach me how to declare a variable in a textbox? I want to use textboxes as input sources for the variables so the program would count on numbers I type there? (the most of tutorials is written in very scientific language so I cant clarify myself good)
Also I know how bad at typing I am and that it lacks capitalization, punctuation, etc (I wasn't listening on language lessons in primary school and this mistake keeps showing off so don't rage at me cause I'm fixing it).

LPINT is a long pointer on int. Thats why you cannot assign a 1 to that variable.

LPINT is a typedef for typedef int *LPINT (http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx)
It's a pointer, not an int.

Related

What happens if I use close() on a char array? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I had an interesting question. I have:
char buf[100]
And I decided to try using close(buf)
Code compiled, the program works. But is there any point in using close() like this?
Thank you.
Assuming "close" is the function from posix, most likely nothing will happen but it's also possible stuff could break badly.
Arrays in c and c++ decay to pointers, close takes an int. Implicitly converting a pointer to an int is not allowed by the c++ spec but some compilers allow it anyway (doing some testing it looks like modern g++ only allows it if -fpermissive is specified).
Most likely the integer that results from said conversion will be large, file descripters are usually small, so most likely close will just return a bad file descriptor error and do nothing but if it does happen to match a file descriptor then things could get interesing.....
It should not compile. The compiler should emit warnings.
The behaviour is undefined
No, there is no point in using close on a char array
There is also no meaning in doing that. What would you want to achieve?

C++ full number of degree [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
This is a simple code that counts two to the right degree. Starting from somewhere around 60 degrees the answer is incorrect.
I need to count 2^200. The answer shouldn't be in the form like "1.606938e+60", but by numbers. How to do this in C++?
#include <iostream>
using namespace std;
int main()
{
unsigned long long int n,z;
cin>>n;
z=pow(2,n);
cout<<z<<endl;
return 0;
}
You need to use std::set_precision(n) to get it to print in the format that you're expecting it, but if your numbers get high enough, you'll run into a second issue. pow returns a double, which loses precision in a big way with huge numbers. For more information on how to solve that, refer to this Stack Overflow answer.
Anyway you cant print such big number as a single integer or double value in c++ (not yet). Maybe there exist some 256 or 512 machine architectures and implementations which build in types are large enough, but its not possible in common. You probably need to use some data structure to store you number and operate on that.
This, this and this examples may be helpful.

Declaring certain elements as const in an array c++, sudoku solver [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is it possible for me to take an existing array and make certain values (not all) constant? I'm trying to build a sudoku solver and my idea is to have the user enter values, so I would like to have those values remain constant as I change the empty spaces. Any tips or advice with the solver would also be appreciated. This is my first quarter working with c++. Thanks!
No. Const is essentially a compile-time idea. It's not something that can be toggled as a program is running.
If you need certain values to remain untouched while others are changed, then you need to put that into your data and logic. For instance, each value might have an associated boolean that indicates whether or not it can be changed. Then write your logic to respect that boolean.

Adding multiple data types to the same variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am relatively new to programming, and I can only really understand C++. I have recently started working on a project that requires the user to input something that will allow them to make a selection. I can't figure out how to make it possible for the user to input a string or a char but get the same result. I know that this would require that I assign the variable that the user inputs (for example 'a') two data types, but how do I do that? I've tried using "string/char a;" but that doesn't work.
Could someone please help me with multi-data-type variables?
Thanks
The string type will work for all user input. Since it "doesn't work" for you, we can't help you further if you don't show us what you tried.
If the User is the one making the Input from the I/O, then you get to decide if you will treat the input as a string or char. After receiving the Input you should know what you want to do with it. And you can also store the input data in array, vectors or list. Primitive data types can do so many things just understand the purpose and function of your program.

C++ - Best Practice: `using std::cout` vs `std::cout` [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I understand that, in C++, we should never use:
using namespace std;
The two possible alternatives are:
1) adding using std::cout; at the beginning of the file and just type cout whenever required
2) type std::cout every time we need to use cout
My understanding is that the second method is the best. However, is this always followed in professional environments? Is it practical to follow in highly fast paced environments? I am used to the first alternative. Is it an advantage to switch?
Note: I originally posted this in Code Review and I was told that this topic belonged here. Kindly let me know if not.
So I have done a little bit with C++, but I would say the problem falls under the problem of namespaces in all languages. The real problem is that if you have multiple namespaces with the same function, it makes it much more difficult to read whats going on and can cause undesired results.
For example if you have two functions with the same name in two name spaces, how will the code know which one to use? Also another problem comes when you have multiple namespaces added and call a function. How does someone reading the code know which namespace the code is coming from? Having the namespace in front of the function helps make your code more readable.