r_cpp | Unsorted

Telegram-канал r_cpp - C++ - Reddit

-

Stay up-to-date with everything C++! Content directly fetched from the subreddit just for you. Join our group for discussions : @programminginc Powered by : @r_channels

Subscribe to a channel

C++ - Reddit

Request GitHub to build an advisory database for C / C++ packages · Issue #2963 · github/advisory-database
https://github.com/github/advisory-database/issues/2963

https://redd.it/18fndiq
@r_cpp

Читать полностью…

C++ - Reddit

Can someone explain this to me?

What does Searched your code for a specific pattern:
.*Andrew\\sMiller\\s69079.36.*

mean?

The program runs fine in the terminal if I use \\t or " ", but MindTap won't count it correct because I think it needs to see that use \\s in the code. I tried to use \\s as a regex and it creates an error in the terminal.

​

Please help!

​

​

https://redd.it/18fkgfd
@r_cpp

Читать полностью…

C++ - Reddit

Talk about performance of passing parameters, struct designs, etc.

A while ago I watched a video on YouTube about C++ performance considerations and differences with different ways of passing parameters into functions. Whether you pass parameters individually, or packaged into structs, how you construct the structs. It was nuanced talking about how 3 parameters differs from 4, etc ...

Anyone know the talk(s) I'm referring you and can direct me? I've spent hours searching now and haven't found them again.

https://redd.it/18fdrsj
@r_cpp

Читать полностью…

C++ - Reddit

Dynamically allocated Array size and number of elements

Hi everyone,

How can I get a dynamically allocated array size in bytes and number of elements.

In a static array, I can calculate both values in this way:
int arr[] = {1,2,3,4};
cout<<sizeof(arr)<<"\n";// size in bytes
cout<<sizeof(arr)<<"\n";// no of elements


While in dynamically allocated array:
int *arr = new int[]{1,2,3,4};
cout<<sizeof(arr)<<"\n";

The above line print size of pointer in bytes not array size so I can't calculate neither size nor no of elements.

Is there any other solutions?

https://redd.it/18f4u5e
@r_cpp

Читать полностью…

C++ - Reddit

Storing data in pointers
https://muxup.com/2023q4/storing-data-in-pointers

https://redd.it/184n4bd
@r_cpp

Читать полностью…

C++ - Reddit

Relearning C++ after C++11
https://www.infoq.com/articles/relearning-cpp-11

https://redd.it/184gugy
@r_cpp

Читать полностью…

C++ - Reddit

Easy graphics library

Hey guys,

Im searching for an easy graphics library in c++ and easy to understand.

Any library?

Thanks ;)

https://redd.it/184c9q1
@r_cpp

Читать полностью…

C++ - Reddit

Dependencies Belong in Version Control
https://www.forrestthewoods.com/blog/dependencies-belong-in-version-control/

https://redd.it/1844d4i
@r_cpp

Читать полностью…

C++ - Reddit

Should I use advanced cpp features?

So I am having a blast reading about all of these cool features of c++: SFINAE (std::enable_if), concepts, polymorphism with CRTP + std::variant and std::visit (type erasure), monadic errors (std::optional + std::expected), CTAD, template specializations, parameter packs, RAII, return type resolver, binds and so on and so forth. Question is, should I "waste" my time using all of these features in my code bases when normal c code would certainly suffice? Is the added complexity ultimately beneficial, even for the largest code bases? Or am I just artificially making the bar of comprehending the code higher purely for syntactic sugar with no practical positive effects, from your experience. Thanks in advance.

https://redd.it/183xx63
@r_cpp

Читать полностью…

C++ - Reddit

Live and Let Die -- Martin Janzen
https://isocpp.org//blog/2023/11/live-and-let-die-martin-janzen

https://redd.it/183z0bs
@r_cpp

Читать полностью…

C++ - Reddit

Thoughts on CLion ?

I've been using it for 2 days and it feels like much lightweight and faster version of Visual Studio. Maybe ill switch to it completly. Thoughts ?

https://redd.it/183tr0s
@r_cpp

Читать полностью…

C++ - Reddit

search words:");
if (targetWords.empty()) {
std::cerr << "Error opening or reading the word list file. Please check the file path and try again." << std::endl;
return 1;
}
std::cout << std::endl;

std::string outputFileName;
std::cout << "Enter the name of the output file: " << std::endl;
std::cin >> outputFileName;

std::ofstream output(outputFileName);
if (!output.isopen()) {
std::cerr << "Error opening or creating the output file. Please check the file path and try again." << std::endl;
return 1;
}

std::vector<int> wordOccurrences(targetWords.size(), 0);
for (const auto& word : allWords) {
for (size
t i = 0; i < targetWords.size(); ++i) {
if (word == targetWordsi) {
wordOccurrencesi++;
}
}
}

for (sizet i = 0; i < targetWords.size(); ++i) {
std::cout << "Word: " << targetWords[i] << ", Occurrences: " << wordOccurrences[i] << std::endl;
output << "Word: " << targetWords[i] << ", Occurrences: " << wordOccurrences[i] << std::endl;
}

BarGraphGenerator::generateBarGraph(targetWords, wordOccurrences, std::cout);
BarGraphGenerator::generateBarGraph(targetWords, wordOccurrences, output);

std::cout << "Results written to " << outputFileName << std::endl;
output.close();

return 0;
}

//ReadWprds.cpp
#include "ReadWords.h"
#include <fstream>
#include <iostream>
#include <cctype>

ReadWords::ReadWords(const std::string& directoryPath, const std::string& fileName) : filePath(directoryPath + "/" + fileName) {}

std::vector<std::string> ReadWords::getWords() {
std::vector<std::string> words;
std::ifstream file(filePath);

if (!file.is
open()) {
// Print an error message if the file cannot be opened
std::cerr << "Error opening file: " << filePath << std::endl;
return words;
}

std::string rawWord;
while (file >> rawWord) {
std::string cleanedWord;

// Remove punctuation and convert to lowercase
for (char c : rawWord) {
if (!std::ispunct(c)) {
cleanedWord += std::tolower(c);
}
}

if (!cleanedWord.empty()) {
words.pushback(cleanedWord);
}
}

file.close();
return words;
}

//ReadWords.h
#ifndef READWORDSH
#define READWORDSH

#include <string>
#include <vector>

class ReadWords {
public:
ReadWords(const std::string& directoryPath, const std::string& fileName);
std::vector<std::string> getWords();

private:
std::string filePath;
};

#endif // READWORDSH

// BarGraphGenerator.h
#ifndef BARGRAPHGENERATORH
#define BARGRAPHGENERATORH

#include <vector>
#include <iostream>
#include <iomanip>

class BarGraphGenerator {
public:
static void generateBarGraph(const std::vector<std::string>& words, const std::vector<int>& occurrences, std::ostream& output);
};

#endif // BARGRAPHGENERATORH

// BarGraphGenerator.cpp
#include <iostream>
#include "BarGraphGenerator.h"

void BarGraphGenerator::generateBarGraph(const std::vector<std::string>& words, const std::vector<int>& occurrences, std::ostream& output) {
int totalWords = 0;
for (int count : occurrences) {
totalWords += count;
}

for (size
t i = 0; i < words.size(); ++i) {
output << std::setw(15) << std::left << wordsi << " | ";

for (int j = 0; j < occurrencesi; ++j) {
output << '';
}

double percentage = static_cast<double>(occurrences[i]) / totalWords
100;
output << " (" << std::fixed << std::setprecision(2) << percentage << "%)" << std::endl;
}
}


&#x200B;

&#x200B;

&#x200B;

&#x200B;

&#x200B;

&#x200B;

&#x200B;

https://redd.it/183jxvr
@r_cpp

Читать полностью…

C++ - Reddit

How did you pass learning curve ?

I've been using python most of the time around 2-3 years for machine learning. Recently ive come across to a paper written by NVIDIA devs called "Instant NGP with a Multiresolution Hash Encoding". Really fascinated about the work and the engineering of this. In real short, they made a thing REALLY FAST by changing algorithms and data structres for GPU to compute it most efficently. As a computer engineer, i think i should be able (and want) to write this kind of low level code in cpp. But the learning curve is so damn frasturating. Even defining a vector iterator seems unnecessary workload to me. How can i keep my motivation up and keep learning ?

https://redd.it/183jyvt
@r_cpp

Читать полностью…

C++ - Reddit

Create towers of hanoi simulation in C++
https://www.youtube.com/watch?v=u1QP9WiOWWM

https://redd.it/183eq7w
@r_cpp

Читать полностью…

C++ - Reddit

Clang vs GCC



https://redd.it/183890u
@r_cpp

Читать полностью…

C++ - Reddit

Cling (interactive C++ interpreter): Release 1.0
https://github.com/vgvassilev/cling/releases/tag/v1.0

https://redd.it/18fl4yb
@r_cpp

Читать полностью…

C++ - Reddit

If you had to start learning programming all over again, what advice would you give to yourself if you could?



https://redd.it/18fgpoq
@r_cpp

Читать полностью…

C++ - Reddit

fkYAML v0.3.0: Support non-string-scalar nodes as mapping keys

fkYAML version 0.3.0 is released! The library now supports non-string-scalar nodes, such as mappings or integer scalars, as mapping keys. Furthermore, GCC-7 and GCC-8 are added to the list of supported compilers. Any kind of YAML tags are not available yet... but will surely be supported in a future release.

https://github.com/fktn-k/fkYAML/releases/tag/v0.3.0

(I know it should be a major update due to some breaking changes according to the rule of semantic versioning, but major updates will be minor updates and the others patch updates before the first major release.)

I'd be very happy if you take a look around, give feedback, or actually use it.

As always, I'm open to any contribution if you would like.

https://redd.it/18f7rft
@r_cpp

Читать полностью…

C++ - Reddit

Approaching C++ programing

Hi everyone, I have been learning C++ programing but I still don't get that which parts I should forcus on diving into them.
Please your way that you have learnt and also practiced on this.
Thanks a lot

https://redd.it/18f3brs
@r_cpp

Читать полностью…

C++ - Reddit

How to declare a pointer to an unknown array size and have a constructor create a dynamic array

Hi!

I'm totally new to programming and I have started learning C++.

I am currently stuck with my assignment on Object Oriented Design, Pointers, File I/O, Exception Handling, Functions and Arrays.

Pointers are really confusing to me. I do not understand how to create a pointer to an array of veggies, where the number of veggies is unknown. Same thing for the pointer to an array of fruits.

I also do not understand how my constructor can read a file and create a dynamic array as my understanding of constructors was that their role was to initialize data members.

&#x200B;

I am currently implementing a class Grocery where,

Attributes:
a pointer to an array of veggies

a pointer to an array of fruits

Constructor():
Reads veggies.txt files and creates a dynamic array of veggies

Reads fruits.txt files and creates a dynamic array of fruits

&#x200B;

&#x200B;

&#x200B;

Thank you very much.

&#x200B;




https://redd.it/184gsl5
@r_cpp

Читать полностью…

C++ - Reddit

Vintage Programming On Macintosh System 7.5 With Think C & ResEdit
jankammerath/vintage-programming-on-macintosh-system-7-5-with-think-c-resedit-5d05c23a8016" rel="nofollow">https://medium.com/@jankammerath/vintage-programming-on-macintosh-system-7-5-with-think-c-resedit-5d05c23a8016

https://redd.it/184cjca
@r_cpp

Читать полностью…

C++ - Reddit

Error in Standard Libraries

I am trying to simulate a page replacement policy of FIFO type

#include <iostream>
#include <vector>
#include<queue>
#include<algorithm>
using namespace std;


int fifo(vector<int> v,int t);
//int lru(vector<int> v,int t);

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>vi;
    }
    int t;
    cin>>t;
   
    int hitfifo=fifo(v,t);
  //int hitlru=lru(v,t);
  cout<<hitfifo<<endl;
}

int fifo(vector<int> v,int t){
    int hit=0;
    queue<int> q;
    for(int i=0;i<v.size();i++){
        if(q.size()<t){
            q.push(vi);
        }
        else{
            if(find(q.front(),q.back(),vi)!=q.back()){
                hit++;
            }
            else{
                q.pop();
                q.push(vi);
            }
        }
    }
    return hit;
}  






this is the code i used, but when i run this the error shown in the vscode terminal is as such:

IMAGE

[{
"resource": "/d:/coding/msys/mingw64/include/c++/12.2.0/bits/stl_algobase.h",
"owner": "cpptools",
"severity": 8,
"message": "no matching function for call to '__iterator_category(int&)'",
"source": "gcc",
"startLineNumber": 2113,
"startColumn": 48,
"endLineNumber": 2113,
"endColumn": 48
},{
"resource": "/d:/coding/msys/mingw64/include/c++/12.2.0/bits/stl_iterator_base_types.h",
"owner": "cpptools",
"severity": 8,
"message": "no type named 'iterator_category' in 'struct std::iterator_traits<int>'",
"source": "gcc",
"startLineNumber": 238,
"startColumn": 5,
"endLineNumber": 238,
"endColumn": 5
}\]

https://redd.it/1844moz
@r_cpp

Читать полностью…

C++ - Reddit

std::mdspan with struct of arrays (SoA) data layout

I have been working on data layouts for a couple of years during my PhD, especially on a uniform looking data layout abstraction. Since std::mdspan already covers a lot of ground I wondered whether I could teach it the struct of arrays (SoA) layout too. I wrote up the story in what turns out to be my first blog post. I would be curious on what other people think on the subject. My goal is to have generic and familiar looking code that I can switch between AoS and SoA in a single place, at best by changing only a single line of code.

https://redd.it/1841pmf
@r_cpp

Читать полностью…

C++ - Reddit

Header Only Library for making bars

Hello guys, I'm making a F1 related C++ project and I'm looking for a header only library that will allow me to create bars with colours much like this. I don't have much experience with external libraries so it would be good if it's user friendly and easy to grasp. Thank you!

https://redd.it/184013p
@r_cpp

Читать полностью…

C++ - Reddit

Herb Sutter's P3021R0 "Unified function call syntax"

I like this a lot. It feel's wisely restrained in its ambition, making it more likely to actually make the cut.

I do have one reservation. I frequently include, within a class, helper methods whose implementations depend only on the class's public API. I do this to provide member call syntax for these helper methods. So I like that fact that P2021 will allow me to implement such helper "methods" outside of the class but still support member call syntax.

I am less wild about the fact that such help methods might also be called using standard function call syntax. I would much prefer a means to declare that, though my helper methods are not privileged methods with access to private or protected members, they may be invoked via member call syntax.

Would adding such a capability undermine any of the virtues Herb claims for his proposal?

https://redd.it/183txmg
@r_cpp

Читать полностью…

C++ - Reddit

On harmful overuse of std::move
https://devblogs.microsoft.com/oldnewthing/20231124-00/?p=109059

https://redd.it/183mz5t
@r_cpp

Читать полностью…

C++ - Reddit

Having issues with building my file for exe, can't work out if it's my code or the compiler

the code is meant to open, get the file from input (Not implemented as i cant get it ito work) get inputted file, thn search for inputted words in a file using an exe, but i cant get it to build properly in both VSC and Clion. After it collects the amount from the file it should create a bargraph

Here is the error====================[ Build | clion_ttempt | Debug \]============================"C:\\Program Files (x86)\\JetBrains\\CLion 2023.2\\bin\\cmake\\win\\x64\\bin\\cmake.exe" --build "M:\\CE221 C++ Programming\\Assignment 1\\ex2\\clion ttempt\\cmake-build-debug" --target clion_ttempt -j 3[1/2\] Building CXX object CMakeFiles/clion_ttempt.dir/main.cpp.obj[2/2\] Linking CXX executable clion_ttempt.exeFAILED: clion_ttempt.execmd.exe /C "cd . && C:\\mingw64\\bin\\c++.exe -g CMakeFiles/clion_ttempt.dir/main.cpp.obj -o clion_ttempt.exe -Wl,--out-implib,libclion_ttempt.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/clion_ttempt.dir/main.cpp.obj: in function `getUserInput(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':M:/CE221 C++ Programming/Assignment 1/ex2/clion ttempt/main.cpp:12: undefined reference to `ReadWords::ReadWords(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: M:/CE221 C++ Programming/Assignment 1/ex2/clion ttempt/main.cpp:12: undefined reference to `ReadWords::getWords[abi:cxx11\]()'C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/clion_ttempt.dir/main.cpp.obj: in function `main':M:/CE221 C++ Programming/Assignment 1/ex2/clion ttempt/main.cpp:58: undefined reference to `BarGraphGenerator::generateBarGraph(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<int, std::allocator<int> > const&, std::ostream&)'C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: M:/CE221 C++ Programming/Assignment 1/ex2/clion ttempt/main.cpp:59: undefined reference to `BarGraphGenerator::generateBarGraph(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<int, std::allocator<int> > const&, std::ostream&)'collect2.exe: error: ld returned 1 exit statusninja: build stopped: subcommand failed.

main.cpp

//main.ppc
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include "ReadWords.h"
#include "BarGraphGenerator.h"

std::vector<std::string> getUserInput(const std::string& prompt) {
std::cout << prompt;
std::string fileName;
std::cin >> fileName;
return ReadWords(R"(M:\CE221 C++ Programming\Assignment 1\ex2\clion ttempt)", fileName).getWords();
}

int main() {
std::vector<std::string> allWords = getUserInput("Enter the name of the text file to be analyzed:");
if (allWords.empty()) {
std::cerr << "Error opening or reading the input file. Please check the file path and try again." << std::endl;
return 1;
}

std::transform(allWords.begin(), allWords.end(), allWords.begin(), (std::string word) {
std::transform(word.begin(), word.end(), word.begin(), ::tolower);
return word;
});

std::vector<std::string> targetWords = getUserInput("Enter the name of the file containing

Читать полностью…

C++ - Reddit

Best Study Resources for Binary Search Trees and AVL Trees?

currently studying a course called Data Structures and Algorithms and we're studying a a chapter called 'Trees'. The thing is that I understand the theory of what we've studied so far like what's a root, leaf, height, making diagrams etc etc but when it comes to implementing them in a c++ code is when i get confused. i think my OOP concepts might be weak as well so does anyone have any study materials they could suggest?

https://redd.it/183jb6a
@r_cpp

Читать полностью…

C++ - Reddit

Visual studio 2022 File Handling

My txt file is not showing up in ifstream , file data is not being read and shown in output . How should i resolve this issue

https://redd.it/183duuz
@r_cpp

Читать полностью…

C++ - Reddit

Suggest me IDE and text editors!

I have probably tried many IDE and text editors but still couldn't find the right one.

Could you guys tell me the IDE or text editors you all use and recommend best one for C/C++?

And yeah I am big fan of Open Source softwares so recommend me best open source ones too.

https://redd.it/18351rj
@r_cpp

Читать полностью…
Subscribe to a channel