[Solved] Instantiating classes using new [closed]

comming from other programming language why can’t I do this in c++: Because in C++ to initilize variable types on the left and right side of = must be compatible. In your case: myClass mc = new myClass(); mc has type myClass and expression on the right has type myClass *. So you either need … Read more

[Solved] Increase stack size c#

What you can do is: If Creation fails pass back a bool and try again from scratch. public void Generate() { Fill(); while(!Fleet()) { // I assume Fill clears your board again?! Fill(); } } public bool Fleet() { return Ship2(Utility.R(1,9),Utility.R(1,9),Utility.R(4)) && Ship3(Utility.R(1,9),Utility.R(1,9),Utility.R(4)) && Ship3(Utility.R(1,9),Utility.R(1,9),Utility.R(4)) && Ship4(Utility.R(1,9),Utility.R(1,9),Utility.R(4)) && Ship5(Utility.R(1,9),Utility.R(1,9),Utility.R(4)); } public bool Ship2(int x, int … Read more

[Solved] How to use map container?

#include <map> #include <string> #include <iostream> std::ostream& operator<<(std::ostream &os, std::pair<std::string, int> const &s) { os << s.first << ” served ” << s.second; return os; } int main() { std::map<std::string, int> servers; servers[“foo”]++; servers[“foo”]++; servers[“foo”]++; servers[“foo”]++; servers[“bar”]++; servers[“bar”]++; for (auto s : servers) std::cout << s << ‘\n’; } solved How to use map container?

[Solved] Compiles in turbo c++. Not in visual studio [closed]

1) Change the beginning of your file from this: #include “stdio.h” #include “string.h” #include “iostream.h” #include “conio.h” to this: #include <cstdio> #include <cstring> #include <iostream> #include “conio.h” using namespace std; 2) Rename the class log to mylog, log is a standard function already defined via #include <iostream>. 3) Remove the calls to clrscr(), there is … Read more

[Solved] Printing contents of a vector [duplicate]

As you mentioned “I did not understand what the code is doing”, let me briefly describe how to iterate through a container: The long way: vector<int> result = { 1,2,3 }; for (vector<int>::iterator it = result.begin(); it != result.end() ; it++) { int i = *it; cout << i << ” “; } Each container … Read more

[Solved] issue with understanding macros in C programming

Macros (#define MACRO …) are processed by the C preprocessor before the actuel compile process takes place. So the compiler only “sees” this once the file has been preprocessed: int main() { // your code goes here int k = 0; scanf(“%d”, &k); switch (k) { case 1: break; case 2: break; case 3: break; … Read more

[Solved] Strange things happen with bool? [closed]

This type of syntax is called a ternary operator. They are generally used to perform simple expressions, or assign things to ONE variable based on a condition, rather than handle assignment logic with two variables. This is why you can’t have both a = TRUE and b = TRUE in the ternary operator. You should … Read more

[Solved] take a word from the user and prints it as shown below. Enter the word: Word d rd ord Word [closed]

To get the expected output, you can make the outer loop loop from word.length() – 1 down to 0 instead: #include <cstddef> // std::size_t #include <iostream> #include <string> int main() { std::cout << “Enter the word:”; if (std::string word; std::cin >> word) { for (auto i = word.length(); i–;) { // <- here for (std::size_t … Read more