Click here to Skip to main content
14,772,946 members
Home » Discussions » C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CString to const char* Pin
_Flaviu30-Aug-19 1:17
Member_Flaviu30-Aug-19 1:17 
GeneralRe: CString to const char* Pin
Victor Nijegorodov30-Aug-19 1:26
MemberVictor Nijegorodov30-Aug-19 1:26 
GeneralRe: CString to const char* Pin
_Flaviu30-Aug-19 2:06
Member_Flaviu30-Aug-19 2:06 
GeneralRe: CString to const char* Pin
Richard MacCutchan30-Aug-19 3:40
mveRichard MacCutchan30-Aug-19 3:40 
QuestionRe: CString to const char* Pin
David Crow10-Sep-19 5:32
MemberDavid Crow10-Sep-19 5:32 
GeneralRe: CString to const char* Pin
_Flaviu30-Aug-19 1:02
Member_Flaviu30-Aug-19 1:02 
GeneralRe: CString to const char* Pin
Richard MacCutchan30-Aug-19 1:57
mveRichard MacCutchan30-Aug-19 1:57 
Questioncpplinq - How to use the aggregate function - Get longest string a string array Pin
Mc_Topaz27-Aug-19 23:24
MemberMc_Topaz27-Aug-19 23:24 
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); // Returns dddd
            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 = "";
	//longest = cpplinq::aggregate();		// ???
	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 Frown | :(

Any suggestions?
AnswerRe: cpplinq - How to use the aggregate function - Get longest string a string array Pin
Graham Breach28-Aug-19 0:13
MemberGraham Breach28-Aug-19 0:13 
GeneralRe: cpplinq - How to use the aggregate function - Get longest string a string array Pin
Mc_Topaz28-Aug-19 0:35
MemberMc_Topaz28-Aug-19 0:35 
Questionerror LNK2019 Pin
_Flaviu27-Aug-19 2:03
Member_Flaviu27-Aug-19 2:03 
AnswerRe: error LNK2019 Pin
Richard MacCutchan27-Aug-19 2:25
mveRichard MacCutchan27-Aug-19 2:25 
AnswerRe: error LNK2019 Pin
phil.o27-Aug-19 3:12
mvephil.o27-Aug-19 3:12 
GeneralRe: error LNK2019 Pin
Richard MacCutchan27-Aug-19 5:31
mveRichard MacCutchan27-Aug-19 5:31 
AnswerRe: error LNK2019 Pin
Stefan_Lang29-Aug-19 22:56
mveStefan_Lang29-Aug-19 22:56 
GeneralRe: error LNK2019 Pin
_Flaviu29-Aug-19 23:09
Member_Flaviu29-Aug-19 23:09 
Questionwarning LNK4099: PDB 'utils.pdb' was not found Pin
_Flaviu26-Aug-19 23:14
Member_Flaviu26-Aug-19 23:14 
AnswerRe: warning LNK4099: PDB 'utils.pdb' was not found Pin
Richard MacCutchan26-Aug-19 23:44
mveRichard MacCutchan26-Aug-19 23:44 
GeneralRe: warning LNK4099: PDB 'utils.pdb' was not found Pin
_Flaviu26-Aug-19 23:51
Member_Flaviu26-Aug-19 23:51 
GeneralRe: warning LNK4099: PDB 'utils.pdb' was not found Pin
Richard MacCutchan26-Aug-19 23:56
mveRichard MacCutchan26-Aug-19 23:56 
Questionwrite a c program to convert decimal no to binary Pin
Devansh Chowdhury23-Aug-19 5:03
MemberDevansh Chowdhury23-Aug-19 5:03 
Rant[REPOST] write a c program to convert decimal no to binary Pin
Richard Deeming23-Aug-19 5:52
mveRichard Deeming23-Aug-19 5:52 
QuestionVS2008 entropy - cannot open project resource views RC1015 error Pin
charlieg23-Aug-19 4:13
Membercharlieg23-Aug-19 4:13 
AnswerRe: VS2008 entropy - cannot open project resource views RC1015 error Pin
Richard MacCutchan23-Aug-19 4:24
mveRichard MacCutchan23-Aug-19 4:24 
GeneralRe: VS2008 entropy - cannot open project resource views RC1015 error Pin
charlieg23-Aug-19 5:27
Membercharlieg23-Aug-19 5:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.