/
i have another question
/
i have this function inline void readSamples () { step ( 4 ); soundfont.samplesCount = read < uint32_t > () / 46; for ( int i = 0; i != soundfont.samplesCount; i++ ) { auto name = readBytes ( 20, true ); auto sampleFrom = read < uint32_t > (); auto sampleTo = read < uint32_t > (); uint32_t samplesCount = sampleTo - sampleFrom; uint32_t samplesSize = samplesCount * 2; auto * temp_sample_aData = new int16_t [ samplesCount ]; memcpy ( reinterpret_cast < char * > ( temp_sample_aData ), audio_data + sampleFrom, samplesSize ); Sample sample ( name, i, temp_sample_aData, read < uint32_t > (), read < uint32_t > (), read < uint32_t > (), samplesSize ); samples.push_back ( sample ); step ( 6 ); } operator delete [] ( audio_data ); } how can i delete the part of the buffer i have readed after reading it
/
but only the part i have readed not everything
/
someone know
Amine
• • • • * • • • ** • • *** • **** How can I use a nested for loop to write this code?
here is code of your problem just change the length with any size of your loop ::
Amine
#include <stdio.h> int main() { int length = 5; for(int i=0 ; i <length ; i++){ for(int j=0 ; j < length-i; j++){ printf("."); } for(int k=0 ;k<=i ;k++ ) printf("*"); printf("\n"); } return 0; }
Pavel
with buffer i mean audio_data
From the code you've pasted I can't see what it is and what it points to.
Hello, I have the following cmake code: add_library(A_LIB_NAME_HERE INTERFACE) ... find_package(BLAS REQUIRED) find_package(LAPACK REQUIRED) target_link_libraries(A_LIB_NAME_HERE INTERFACE ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}) ... install(TARGETS A_LIB_NAME_HERE EXPORT A_LIB_NAME_HERE-target) install(EXPORT A_LIB_NAME_HERE-target FILE A_LIB_NAME_HERE-config.cmake DESTINATION lib/cmake/A_LIB_NAME_HERE) The result xxx-config.cmake contains ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} directly. I want to let it contains find_package(BLAS REQUIRED) find_package(LAPACK REQUIRED) target_link_libraries(A_LIB_NAME_HERE INTERFACE ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}) that is to say find BLAS and LAPACK when using the library after installation, instead of when installing. How to do it?
/
new int16_t [ sizw ]
Pavel
i dont know but it is an int16_t pointer
Then it's C array, look at my message above, you can't deallocate part of it
Pavel
but if i use a vector do it use more memory
It depends, it usually preallocates some memory in advance to decrease amount of allocations (if it wouldn't do that, every addition of an element would be an allocation and copying all existing elements to the new memory). But you can control that, you can ask to preallocate memory for the the desired amount of elements by calling reserve, or just create them right away with resize. As far as I remember, both of them should allocate only memory needed to fit them and no more. You can check that yourself by checking value of what capacity returns.
Pavel
the problem is that the audio data array may be very big
How big? If it would fit into C array, it will also fit into std::vector
Pavel
I mean if you can reliably allocate big enough chunk of memory for it on your target platform
/
How big? If it would fit into C array, it will also fit into std::vector
yes so the vector will not use more memory than the c array
Pavel
yes so the vector will not use more memory than the c array
If you preallocate it with reserve or resize it shouldn't. Except for two more variables for size and capacity.
Pavel
/
Example of what?
i dont understanded
Pavel
i dont understanded
Don't understand what exactly?
Pavel
if the vector is bigger
this? https://wandbox.org/permlink/A9uHrXWfFasw4FZC
Llll
Guys, I have this problem concerning asymptotic complexity. I understand that the efficiency of an algorithm is independent of the processing power as the processing power only adds a constant to the order of the algorithm which is kinda irrelevant when considering the order of the algorithm after the speedup. Simply put, a badly written algorithm will perform badly no matter how powerful a processor processing it is. So considering an algorithm with a linear time complexity, it is immediately obvious that speeding up the processor processing the algorithm tenfold, should allow a problem size ten times the problem size of the algorithm running on the unmodified processor to be executed in just the same amount of time as would the same algorithm running on the unmodified processor (with the original problem size). So how does a processor speedup also by tenfold affect an algorithm with a quadratic time complexity? I know that it cannot be an improvement by a factor of 10 but rather less, which is sqrt (10), except I am unable to derive intuitively how it all comes together.
Lawal
Hi
кар карыч
hello, I ran into a problem that Visual Studio 2017 gives errors in standard libraries, writes that "C2143 syntax error: missing ")" before "constant" x) C"
кар карыч
and so in many files like math.h
A
https://leetcode.com/problems/reverse-bits/discuss/2283682/Help-needed-C%2B%2B-code
A
help needed here can anyone help me out
A
class Solution { public: uint32_t reverseBits(uint32_t n) { uint32_t q=pow(2,31); uint32_t b = 0; if( n == 0){ return b; } for(uint32_t i=1;i<=(q-1);i++){ if(n & 1){ b = b | 1; b = b << 1; n = n >> 1; } else{ b = b | 0; b = b << 1; n = n >> 1; } } return b; } };
A
code to reverse bits of integer
Submissive
#include <bits/stdc++.h> using namespace std; void removeDupWord(string str) { string word = ""; for (auto x : str) { if (x == ' ') { cout << word << endl; word = ""; } else { word = word + x; } } cout << word << endl; } // Driver code int main() { string str = "Geeks for Geeks"; removeDupWord(str); return 0; } This code splits the line into words What does that for loop mean? Can we use colon inside for loop()
Buffer
#include <bits/stdc++.h> using namespace std; void removeDupWord(string str) { string word = ""; for (auto x : str) { if (x == ' ') { cout << word << endl; word = ""; } else { word = word + x; } } cout << word << endl; } // Driver code int main() { string str = "Geeks for Geeks"; removeDupWord(str); return 0; } This code splits the line into words What does that for loop mean? Can we use colon inside for loop()
#include <iostream> #include<string> using namespace std; void removeDupWord(string str) { string word = ""; for (int x=0 ; str[x] != '\0' ; x++) { if (str[x] == ' ') { cout << word << endl; word = ""; } else { word = word + str[x]; } } cout << word << endl; } // Driver code int main() { string str = "Geeks for Geeks"; removeDupWord(str); return 0; }
Buffer
It is the semicolon form of for loop
Buffer
That was range based for loop in c++ and added since c++ 11
Shappa
Where do I start as a newbie
Shappa
!?
المبرمج طارق
Mahsun
Where do I start as a newbie
https://hackingcpp.com/index.html
Sylvester Lim
Hi all, I am making a game where each player will pick a card and then see who wins, then this repeats for 5 rounds ... and they can choose whether to continue playing after the 5 rounds or not. I want to output the game logs into an output file where I used this method below : int main{ do{ recordGameLogs(); // i call my function to record game logs here }while(round <=5) //make the game run for 5 rounds return 0; } void recordGameLogs() { ofstream outfile; outfile.open("testwritezzz.txt", ios::app); // i used append mode to make sure that data is not overwritten after every round(as the game is played for at least 5 rounds) if(outfile) { outfile << "Game Log --> Round " << roundNum <<endl; outfile << "________________________________" << endl; outfile << "(all player details etc etc)" } The code I sent is not complete, I just wanted to show a rough skeleton of the program. Anyways I used ::app , which is append mode to make the data be succesffuly written for all 5 rounds, if I just left it without append mode or trunc mode, the output file only records Round 5 details(as round 1 to 4 details are being overwritten). However, if i were to exit the program and decide to run it again , the previous game logs are still there. Is there any way for it to clear previous output content when the program is terminated, so everytime I run it only records the newest 5 rounds played .
Anonymous
Anyone up for pair programming?
/
hi i have a problem
/
std::ifstream * file; bool open ( char * fileName ) { file -> open ( fileName, std :: ios :: binary ); return file -> is_open (); }
/
why this crashes
/
it isnt a problem of the file name
Sandy
😄
/
😄
to me
/
i have solved it
/
but how i get the current offset with fstream
/
the position
/
i tried tellg it returns 0
/
no wait it doesnt
Kirk
hi, i'm having problems initializing a bi-dimensional vector in a class: https://pastebin.com/RYAH2Q2D compiling with g++ i get "error: ‘V’ is not a type"
Saleh
hello i can't use include filesystem on codeblock 13.12 how i can solve that problem?
Saleh
Usha
Hi anyone there to start from basics?
Pavel
hello i can't use include filesystem on codeblock 13.12 how i can solve that problem?
Can you check what version of the compiler you use and whether you've enabled C++17
Pavel
hello i can't use include filesystem on codeblock 13.12 how i can solve that problem?
You can also try to include <experimental/filesystem> if you use some compiler version that have it in experimental state
\Device\NUL
it is gcc 4.8.1
What standard ?
Saleh
What standard ?
gcc <tdm>-2>
\Device\NUL
*Confused nick young
\Device\NUL
gcc <tdm>-2>
Try -std=c++17 flag, And make sure you use g++ and not gcc
Anonymous
Nani?
Huh?
pavel
Huh?
What does it mean?
Anonymous
What does it mean?
U Don't know pair programming?
pavel
Saleh
Try -std=c++17 flag, And make sure you use g++ and not gcc
error: unrecognized command line option '-std=c++17'
\Device\NUL
error: unrecognized command line option '-std=c++17'
Seriously, are you using C++ compiler and not C ?