Need guides in understanding the C++ codes [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
can someone explain me on what does these codes did? this is only part of the code...
// Create the window of the application
sf::RenderWindow myWindow(sf::VideoMode(myWorldWidth, myWorldHeight, 32), "Battleship!");
myWindow.setVerticalSyncEnabled(true);
bool showHardwareMouse;
bool started;
bool drag;
float dragOffsetX, dragOffsetY;
bool LeftMouseButtonDown = false;
bool reset = true;
//----- Main Loop Start here -----
while (myWindow.isOpen())
{
if (reset)
{
// Reset
showHardwareMouse = true;
drag = false;
dragOffsetX = dragOffsetY = 0.0f;
started = true;
reset = false;
}
the program is actually based on SFML library, what does dragOffsetX = dragOffsetY = 0.0f; means?
and this is how actually the program work like...
http://i1146.photobucket.com/albums/o530/HTHVampire/C%20plus%20plus/Capture2_zps1fe188cd.jpg
I will post the full codes of it if you guys can't get it. Thanks!

dragOffsetX = dragOffsetY = 0.0f;
is the same as
dragOffsetX = (dragOffsetY = 0.0f);
where an assignment a = b has the "value" b. So the above line is the same as:
dragOffsetX = 0.0f;
dragOffsetY = 0.0f;
The rest of the code consists mainly of declarations and initializations and should be obvious.

Related

C2027 can't use Stringbuf in MVSC [closed]

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 days ago.
Improve this question
I've an issue using stringbuf in MVSC
stringbuf is a basic std type from iostream which is included above that block code.
for example a method using stringbuf reference :
`bool SJsonMon::Initialize(const stringbuf& DeviceP)
{
/*
******************************************************
*** Init lifetime monitor
******************************************************
*/
DeviceParameters = json::parse(DeviceP.str());
if (DeviceParameters["TypeElement"] == "LS14250")
{
mRL_MonitorLifetime_M.RL_MonitorLifetime_InstP_ref = &RL_LS14250_MonitorLifetime_P;
}
else if (DeviceParameters["TypeElement"] == "LS14500")
{
mRL_MonitorLifetime_M.RL_MonitorLifetime_InstP_ref = &RL_LS14500_MonitorLifetime_P;
}
else if (DeviceParameters["TypeElement"] == "LS17500")
{
mRL_MonitorLifetime_M.RL_MonitorLifetime_InstP_ref = &RL_LS17500_MonitorLifetime_P;
}
else if (DeviceParameters["TypeElement"] == "LS26500")
{
mRL_MonitorLifetime_M.RL_MonitorLifetime_InstP_ref = &RL_LS26500_MonitorLifetime_P;
}
else if (DeviceParameters["TypeElement"] == "LS33600")
{
mRL_MonitorLifetime_M.RL_MonitorLifetime_InstP_ref = &RL_LS33600_MonitorLifetime_P;
}
mRL_MonitorLifetime_M.blockIO = &mRL_MonitorLifetime_B;
mRL_MonitorLifetime_M.dwork = &mRL_MonitorLifetime_DW;
/* Pack model data into RTM */ // Context to back up
// Initialization input output for step method
RL_MonitorLifetime_initialize(
&mRL_MonitorLifetime_M,
&mRL_MonitorLifetime_U,
&mRL_MonitorLifetime_Y);
// Pack Device parameters in json object
DeviceParameters = json::parse(DeviceP.str());
return 1;
}`
the error :
Erreur C2027 utilisation du type non défini 'std::basic_stringbuf<char,std::char_traits<char>,std::allocator<char>>'
Is someone can help about that issue?
Thanks a lot!
I used this code on stm32IDE and it worked and I decide to export the project on MVSC to simplify the DLL compilation.

in c++ how to loop an array in return statement [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 1 year ago.
Improve this question
public async Task < IActionResult > Events(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest httpRequest,
ILogger log) {
ValidateResponse res = eventService.ValidateSchema();
if (res.Valid == false && res.Errors != null) {
string[] messages = new string[100];
int k = 0;
for (int i = 0; i < res.Errors.Count; i++) {
string value = res.Errors[i].ToString();
if (value.StartsWith("Invalid type")) {
messages[k++] = value.Substring(10);
continue;
}
}
return new OkObjectResult($ "No of events posted {cloudEvents.Count} and errors :{messages[k]}");
}
But the values in messages are not returned. I understand that its an array . But unable to figure out the ways to loop here in return all array values once.
Once option is to join the messages array to a string:
return new OkObjectResult($"No of events posted {cloudEvents.Count} and errors:{String.join(\",\", messages}");

Using single else statement for multiple if conditions [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 3 years ago.
Improve this question
I am coding for an arduino project and i came across this problem, can anyone help me out!
if(condition1){
//my codes here
}
if(condition2){
//my codes here
}
if(condition3){
//my codes here
}
......
if(condition100){
//my codes here
}
else{
my codes here
}
I want to check all my if conditions, and execute the codes if the conditions are true, and run the else statement only if none of the if condition become true.
Note that i cant use else if because i want to check all the if conditions, and if none are true i want to run the else
If conditions are not dependent on each other
You can use a Boolean flag which is set in any of your ifs.
bool noPathTaken = true;
if ( condition1 ) {
noPathTaken = false;
// ...
}
if ( condition2 ) {
noPathTaken = false;
// ...
}
// ...
if ( noPathTaken ) { // this would be your "else"
// ...
}
must set off all else flag in each test
bool elseFlag = 1;
if(condition1){
elseFlag = 0;
my codes here
}
if(condition2){
elseFlag = 0;
my codes here
}
if(condition3){
elseFlag = 0;
my codes here
}
......
if(condition100){
elseFlag = 0;
my codes here
}
if (elseFlag) {
my codes here
}
because else gets binded only into preceding test operation, here if(condition100) {

SEH Eceptions - generating and handling [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
I want to generate and handle exceptions (SEH).
How can I write a code that will lead to an "illegal instruction"-exception?
You can do something like this:
#include <Windows.h>
#include <cstdio>
::DWORD FilterFunction(::DWORD const _exception_code)
{
if(EXCEPTION_ILLEGAL_INSTRUCTION == _exception_code)
{
::std::printf("filtered\n");
return EXCEPTION_EXECUTE_HANDLER;
}
else
{
::std::printf("not filtered\n");
return EXCEPTION_CONTINUE_SEARCH;
}
}
int main()
{
__try
{
::std::printf("trying...\n");
::RaiseException
(
EXCEPTION_ILLEGAL_INSTRUCTION // exception id
, 0 // continuable exception
, 0 // args count
, nullptr // args
); // no arguments
::std::printf("finished trying\n");
}
__except(FilterFunction(GetExceptionCode()))
{
::std::printf("exception handled\n");
}
return 0;
}
trying...
filtered
exception handled
You can raise a structured exception in Windows with:
RaiseException(EXCEPTION_ILLEGAL_INSTRUCTION, EXCEPTION_NONCONTINUABLE, 0, nullptr);
Reference:
https://msdn.microsoft.com/en-us/library/ms680552%28VS.85%29.aspx

Listing Threads c++ [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 9 years ago.
Improve this question
this code it lists all processes and all threads of the process, but I want it lists only the thread of a process by pid ... example: explorer.exe pid = 5454 through the pid wanted him to have the ids of threads and thread state.
How about passing the process ID as a command line argument to the program and filter out the content required.
while( pi )
{
SYSTEM_PROCESS_INFORMATION* next = PROCESS_INFORMATION_NEXT( pi );
UINT32 count, n;
if (argc > 1 && pi->UniqueProcessId == (HANDLE)atoi(argv[1])) {
printf("**************************************\n");
if( pi->ImageName.Buffer )
wprintf(L"%u %s <------ PROCESSO\r\n", pi->UniqueProcessId, pi->ImageName.Buffer);
else
wprintf(L"%u %s *\r\n", pi->UniqueProcessId, L"System Idle Process");
if( next )
count = ThreadCount( pi, (ULONG_PTR)next );
else
count = ThreadCount( pi, (ULONG_PTR)spi + size );
for( n=0; n<count; n++ )
{
SYSTEM_THREAD_INFORMATION* th = pi->Threads + n;
wprintf(L" [%u] StartAddress=%p ID Processo=%u IdThred=%u State=%u \r\n",
n+1, th->StartAddress, th->ClientId.UniqueProcess, th->ClientId.UniqueThread,th->WaitReason);
}
}
pi = next;
}
you can see this on msdn
i think this is what you are looking for.