I am creating a graphical application using the SFML library. I have a class, Square, that creates a square block with a letter inside. This class has members sf:: Font and sf::Text except for the square itself (sf::RectangleShape). The constructor of this class takes the size of the side of the square, its position, the ..

#### Category : vector

I have a problem similar to the one mentioned in the question Convert vector of vector to pointer of pointer. The only difference is that I have to use booleans instead of shorts. But if I compile this code: #include <vector> /* C like api */ void foo(bool **psPtr, const int x, const int y); ..

I have this code: int a[4][4]= { {1,2,3,4}, {5,6,7,8}, {9,10.11.12}, {13,14,15,16} } And I want to initialize B which is defined as below: vector<vector<int>> b; I know that I can do this with two loops (and possibly with one loop as documented here: https://stackoverflow.com/a/4092996/654019 But is there any way that I can do this without ..

You are given a read only array of n integers from 1 to n. Each integer appears exactly once except A which appears twice and B which is missing. Return A and B. Here is the solution tried : vector<int> Solution::repeatedNumber(const vector<int> &A) { int n=A.size(); vector<int> res(2); unordered_map<int, int> m; for(int i=0;i<n;i++){ m[A[i]]++; if(m[A[i]]==2) ..

i want to define the two dimensional string , not a char vector in C++ Like this : vector<vector<char>> vect { {"Simple", "Simple", "Simple"}, {"Simple", "Simple", "Simple"}, {"Simple", "Simple", "Simple"} }; Thanks Source: Windows Que..

I am trying to do dfs traversal using recursive call, My Graph, and vector<int>visited are global variables. num_v variable corresponds to number of vertices,num_e corresponds to number of edges I tried calling two DFS calls in main, but my output matches to the correct DFS order for the first case. and it gives incorrect out ..

I would like to have a concept requiring as return type an arbitrary vector: template<typename T> concept HasVector = requires (T t) { { T.vec() } -> std::same_as<std::vector<int>>; //works { T.vec() } -> std::same_as<std::vector<foo>>; //want to put something arbitrary in here } Such that we would have something like the following: class A { std::vector<int> ..

The vector is std::vector<vector2> assualt_rifle = { {-35, 50},{5, 46},{-55, 42},{-42, 37},{0, 33},{16, 28},{29, 24},{38, 19},{42, 14},{42, 9},{38, 9},{30, 18},{17, 25},{0, 29},{-15, 32},{-27, 33},{-37, 32},{-43, 29},{-46, 24},{-45, 17},{-42, 8},{-35, 5},{-24, 14},{-11, 21},{12, 25},{36, 28},{49, 28},{49, 26},{38, 21}}; I need to get the delta between the current element of the vector and the previous one. After ..

Trying to solve ‘move zeros’ question. I have to shift all zeros of vector at last and then all other numbers need to be arranged in ascending order. class Solution { public: void moveZeroes(vector<int>& nums) { int position = nums.size()-1; for(int i=0;i<nums.size();i++){ if(nums[i]==0 && nums[position]!=0 && position>=i){ int temp=nums[i]; nums[i]=nums[position]; nums[position]=temp; position-=1; } for(int i=0;i<nums.size();i++){ ..

I have a struct called Person: Person { int id; int age; int salary; }; so I want to enter as many Person as I want with the standard input in the following form: [id, age, salary] [id, age, salary] … in one line. so I did write this code but it doesn’t give me ..

## Recent Comments