|
Good idea. I have used CreateFileA, and I get rid of that "access denied". But there a thing that I had afraid: the original code, with _open returned int, and CreateFileA return HANDLE ... casting HANDLE to int is OK ? I guess not ...
|
|
|
|
|
How are you going to use the handle returned from _open ?
|
|
|
|
|
Windows has GetLastError you notice CreateFile Simply returns invalid handle for an error if you get that then you call GetLastError
GetLastError function (errhandlingapi.h) | Microsoft Docs[^]
That is the equivalent of your original int it's just a non zero number identifying the error, 0 always equals no error.
In vino veritas
|
|
|
|
|
Programming.. Backtracking.
I need help with backtracking question.
In an election, five parties won and got
A 20
B 14
C 30
D 16
E 40
In order to rule, a coalition of More than 60 must be negotiated. But we have restrictions:
A does not sit with D
C does not sit with E
A B C D E
A. 1 1 1 0. 1
B. 1 1. 1 1. 1
C. 1 1. 1 1. 0
D 0 1. 1 1. 1
E. 1. 1. 0. 1. 1
The function should return the number of possible coalitions.. Which is 3.
As soon as the coalition is formed, no need to add more parties.
A + E + B is not valid
|
|
|
|
|
This is a mathematical/logic question, which you need to solve first. Once you have done that then writing the code should be straightforward.
|
|
|
|
|
Washiko wrote: A + E + B is not valid
I don't see why not. Above the condition was stated that
Washiko wrote: a coalition of More than 60 must be negotiated
which means neither A+E nor A+B or B+E would be enough - all three are needed to get more than 60.
As for your program, if you don't know what backtracking means, look up recursion and backtracking. There's nothing difficult about coding these concepts in C. If you do know what it means, write a program and, if at any point you're stuck, show the code you're stuck with.
We don't write full programs for other people on request. If it's homework, we'd do you a disfavor by destroying a chance for you to learn. If it's work, you'd get paid, and you can't expect from others to do that work for you without payment. If it's a contest, it's part of the contest to find out how to write the program - if others do it for you it tells nothing about your skills, and it would be unfair to the other contestants.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Hi,
currently I am comparing the MeshCommander and the Intel Manageability Commander for configuring AMT Version 12.
With the MeshCommander I was able to configure AMT Version 12 for a TLS connection.
But I found no way to do the same with the Intel Manageability Commander.
1. Where are the setting in the Intel Manageability Commander for TLS configuration?
2. How can I configure TLS with Intel Manageability Commander?
Regards and thanks in advance for helpful answers
jo123
|
|
|
|
|
This has nothing to do with C/C++/MFC, or indeed software in general. Please find a more appropriate forum.
|
|
|
|
|
I am trying to convert a CString to const char*, and I have tried some versions:
CString sTemp("abcd");
const char* chTemp = (LPCSTR)(LPCTSTR)sTemp;
is one of them, but in chTemp I have only one letter from sTemp, not whole string ... why ?
|
|
|
|
|
|
I have converted the project to multi-byte character set (was unicode) and the behavior is the same ...
|
|
|
|
|
I have tried this also:
const char* chTemp = (const char*)sTemp.GetBuffer(0);
sTemp.ReleaseBuffer();
TRACE(">>>>>>>>>>>>>>>>>>>%s\n", chTemp);
the project is not multi-byte ... the same result, just one letter (first letter) from the string ...
|
|
|
|
|
_Flaviu wrote: the project is not multi-byte
Is it "not multi-byte" or "multi-byte"?
|
|
|
|
|
Sorry, is multi-byte .. .anyway, if the project is unicode or is multi-byte, is the same thing.
|
|
|
|
|
Try these tests:
CStringA ansiText("TestA");
LPCSTR ansi = (LPCSTR)ansiText;
TRACE("%s\n", ansi);
CString someText("Test");
ansi = (LPCSTR)someText;
TRACE("%s\n", ansi);
What is the result?
|
|
|
|
|
with the first try:
CStringA ansiText("TestA");
LPCSTR ansi = (LPCSTR)ansiText;
TRACE("%s\n", ansi);
the result is TestA
for the second try, I got an error:
1>d:\tempx\test\testdoc.cpp(53): error C2440: 'type cast' : cannot convert from 'CString' to 'LPCSTR'
at
CString someText("Test");
ansi = (LPCSTR)someText; TRACE("%s\n", ansi);
The project is unicode.
|
|
|
|
|
_Flaviu wrote: for the second try, I got an error:
1>d:\tempx\test\testdoc.cpp(53): error C2440: 'type cast' : cannot convert from 'CString' to 'LPCSTR'
at
CString someText("Test");
ansi = (LPCSTR)someText; TRACE("%s\n", ansi);
The project is unicode. |
Of course you get the error since the CString contains the wide char text!
Either change the build to be MBCS/ANSI or convert CString to wchar_t* (or use _T() macro).
|
|
|
|
|
"build to be MBCS/ANSI" you meant multi-byte project ?
|
|
|
|
|
Go to Project -> Properties -> General and make sure Character set is set to "Use Multi-Byte Charachter Set".
|
|
|
|
|
_Flaviu wrote:
TRACE(">>>>>>>>>>>>>>>>>>>%s\n", chTemp); What if you try:
TRACE(">>>>>>>>>>>>>>>>>>>%S\n", chTemp);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Is obviously something in project settings, because I have tried this code in a new test project and goes fine as multi-byte project ... as unicode, the same result.
|
|
|
|
|
You cannot cast a CStingW (which is what the class will be in a Unicode environment) to an LPCSTR (which is const char* ). You need to show again the actual failing code, and check the project settings.
|
|
|
|
|
In an array of strings I would like to get the string containing the most characters.
There are, of course, many ways to solve this, but coming from C# I find LINQ being an elegant tool.
I found out that the cpplinq NuGet package give me the same LINQ library as in C#.
For my problem - get the longest string in a string array - I can use the LINQ's aggregate function.
In C#, I have looked it up, and it can be solved like this:
using System;
using System.Linq;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var words = new string[] { "a", "bb", "ccc", "dddd" };
var longest = words.Aggregate("", (max, cur) => max.Length > cur.Length ? max: cur);
Console.WriteLine(longest);
}
}
} I cannot understand how to do this in C++ with the cpplinq package. Basically just porting the C#'s call to a C++'s call of the aggregate function.
#include "pch.h"
#include "cpplinq.hpp"
#include <iostream>
#include <string>
int main()
{
std::string words[4] = { "a", "bb", "ccc", "dddd" };
auto longest = "";
std::cout << longest << std::endl;
} I have googled for an example in c++ how to use the Aggregate function in cpplinq package, but with no result
Any suggestions?
|
|
|
|
|
I've just tried it out here and it seems easy enough:
using namespace cpplinq;
std::string words[4] = { "a", "bb", "ccc", "dddd" };
auto longest = from_array(words)
>> aggregate(std::string(), [](const std::string &m, const std::string &c) {
return m.length() > c.length() ? m : c; });
(I renamed the variables to "m" and "c" because I got an error message about max being a function.)
|
|
|
|
|
Thank you!
Man! I would have never guessed the porting would look like that 
|
|
|
|