[Solved] How to compare a string with a struct (which include strings too)? [closed]

I think you should be comparing the string WITHIN the struct. Username[i].usernameadmin == username This would compare string username with string usernameadmin. The == operator can be used to compare strings in C++, thanks to overloading. You can still use .compare as well. Username[i].usernameadmin.compare(username) 10 solved How to compare a string with a struct (which … Read more

[Solved] Few questions about initialization and lambda in c++ [closed]

Ad 1. You’ve been bitten by the most vexing parse. Basically, C++ grammar causes ambiguities between statements and declarations in certain cases. In such cases, the input is interpreted as a declaration. Since int i() can be interpreted as an integer variable definition, or a function declaration, it is interpreted as a declaration of parameterless … Read more

[Solved] C++ Using Class to Define New Type

Defining a constructor that takes a const char* as parameter and a copy constructor should do it. Having a copy constructor there also means you’d need a copy assignment operator and a destructor. You should also decide whether your objects assume ownership of the strings. In your example – a.value = “Hello, “; – just … Read more

[Solved] Program fails to open file

In string literals, the “\” slash is the escape character. In order for your string literal to work properly you need to escape each “\” with the “\”. In other words, replace each “\” with two slashes like so: inFile.open(“C:\\Users\\Muhammad Shaeel\\Desktop\\CC\\Lexical Analyser Code\\Lexical Analyser Code\\program.txt”); solved Program fails to open file

[Solved] does cout before return statement of recursive function stops it?

The body of an if-statement can be either a compound statement, which is a list of statements surrounded by {}, or it is the single statement following the if‘s condition. That means that this code: if(n>=2) cout<<“number of times the function called: “<<endl; return n*factorial(n-1); is completely equivalent to: if(n>=2){ cout<<“number of times the function … Read more

[Solved] How can I iterate through a array filled with structures?

If you’ll do it often, define a stream operator for your struct, then loop over them (see it live on Coliru): #include <iostream> struct PlayerState { char name[20]; int level; int year; double health; int experience; }; std::ostream& operator<< ( std::ostream& os, const PlayerState& state ) { os << state.name << “: ” << state.level … Read more

[Solved] Error input string was not in correct formalt

I think just you need to check the value of your textbox first cause you can`t convert null value to Double if (textBox1.Text!=””) { m = kilometer * Convert.ToDouble(textBox1.Text);//here is the problem textBox2.Text = m.ToString(); } or give textBox1 initial value before start calculation, Note: If you use number Regex for TextBox1 this will be … Read more

[Solved] why my password isn’t changed?

this part: cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); cmd.Dispose(); cmd = null; db.Close(); db.Open(); SqlDataReader DR; DR = cmd.ExecuteReader(); why do you execute a non query, which is a query (select * from …)? why do you dispose the SqlCommand object cmd and why do you reuse it after disposing? why do you close and open the line below? … Read more

[Solved] Make a triangle shape in C++ [duplicate]

This code works fine for a right angled triangle – * ** *** But I guess you want a triangle like this – * *** ***** Try this – #include <iostream> using namespace std; int main() { int i, j, k, n; cout << “Please enter number of rows you want to see: \n”; cin … Read more