[Solved] What does “[&]” mean in C++?

This statement uses a lambda expression. auto updateSlack = [&](const char slack_type, const double s) { if (slack_type == ‘e’) { wns.early_slack = min(s, wns.early_slack); tns.early_slack += s; } else if (slack_type == ‘l’) { wns.late_slack = min(s, wns.late_slack); tns.late_slack += s; } }; The compiler does two things. The first one is that the … Read more

[Solved] program to delete certain text which is predefined in another file from a file in c++

Show some research effort when you post a question here. #include <iostream> #include <unordered_set> #include <fstream> int main() { std::unordered_set<std::string> mySet; std::string word; std::ifstream file1(“myFile1.txt”); if(file1.is_open()) { while(file1 >> word) mySet.emplace(word); file1.close(); } std::ifstream file2(“myFile2.txt”); if(file2.is_open()) { while(file2 >> word) { auto look = mySet.find(word); if(look != mySet.cend()) mySet.erase(look); } file2.close(); } std::ofstream outputFile(“Out.txt”); if(outputFile.is_open()) … Read more

[Solved] My codes work well In Dev c++ IDE, but in linux terminal, it doesn’t. (especially in the part of ‘while’ loop.) [closed]

You are most likely running into the NL/CR issue. Instead of if (a[i]==””) Use something like: if (isEmptyLine(a[i])) where bool isEmptyLine(std::string const& s) { for ( auto c : s ) { if ( !std::isspace(c) ) return false; } return true; } You can also convert the file into a file with UNIX style line … Read more

[Solved] Array not displaying proper output

Because in your conditions, you check if(hoursWorked[i] < 40) and if(hoursWorked[i] > 40), but there is no condition for if(hoursWorked[i] == 40). You probably wanted to use -or-equal operator on one of these conditions (>= or <=). solved Array not displaying proper output

[Solved] C++: Using for loop I need to take infinite values of a point using arrays. How can I take values of point [ ] until 2 points of are equal

To test if two consecutive numbers are equal, you dont need 100 elements, you need 2: int points[2], counter = 1; // Read in first point: cin >> points[0]; // Read until we meet our condition: do { // Read a point into the next part of the array. cin >> points[counter]; // toggle counter … Read more

[Solved] Three type of Balls from Bag

If K>max(R,G,B) then the problem has no solution. So let’s assume K <= max(R,G,B). If you don’t have any control over which ball gets extracted, you’ll need at most (i.e. this is a lower bound) min(R, (K-1))+min(G, (K-1))+min(B, (K-1))+1 extractions for obvious reasons: extract K-1 red balls (or all red balls if R<K), then extract … Read more

[Solved] Extracting string from text [closed]

Not the most elegant solution but this should work #include <iostream> #include <vector> #include <string> #include <sstream> using namespace std; vector<string> split(string str, char delimiter) { vector<string> internal; stringstream ss(str); string tok; while(getline(ss, tok, delimiter)) { internal.push_back(tok); } return internal; } int main(int argc, char **argv) { string str = “My name is bob.I am … Read more

[Solved] Deleting word from file evertime user enters a word to delete and writing the new array to a new file. C++

string space = ” “; int locate = -1; for (int j = 0; j < dictionarySize; j++) { if (space == d_newDictionaryArray[j]) { locate=j; break; } } //to locate where the element with space is stored if(locate!=-1) for (int i = locate; i < dictionarySize-1; i++) { d_newDictionaryArray[i] = d_newDictionaryArray[i+1]; } //to shift all … Read more

[Solved] Difference between , and ;?

You have not written a copy constructor or a copy assignment operator. The Rule of 3 tells us that anytime a destructor has been written, the copy assignment operator and copy constructor should be as well. You haven’t written either so let’s look at what happens: l3 = l1 in this line the implicitly defined … Read more