String comparison function (c++) [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am looking for a function to compare the two strings. A functional similar to strcmp in CString with the difference that takes two strands in the input.

You can use std::string::compare (it returns 0 if values are the same). Also be aware that in fact you can use strcmp in c++, but if you want modern c++ version i would go with std::string::compare.

Related

CPP intresting thing with conditionsl statement [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
if(cout<<"h"){}
this gives me an output
h
Any idea why, I have tried many variations of it and it still works.
That's because the if statement needs to evaluate the condition you give into it, plus, streams are implicitly convertible to bool.

From String to Function [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'd like to know if there is a way to transform a string into a function em c++. For example if I have the string: "x+y" it'd create the function and by replacing x and y, get the value of it.
In Java there is this API https://www.objecthunter.net/exp4j/index.html, so I was wondering if there is something similar.
There are many possible methods one could use to transform a string into a "function". Many of those involve parsing the string and building a function-like object out of it.
A lightweight and portable solution would be to use ExprTk, a mathematical expression library developed by Arash Partow.
The main page contains various usage examples.

How likely is istream::ungetc() to work with a stringbuf (as used in stringstream)? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I've tried searching for the answer, but nothing mentions stringstream specifically. I would guess that it would always work and you can always go back as far as the beginning of the underlying string.
Am I right?
How likely is istream::ungetc() to work with a stringbuf (as used in stringstream)?
Well, never.
There's no such thing like istream::ungetc() defined from the standard.
You can use either
int std::ungetc( int ch, std::FILE *stream )
or
std::basic_istream& std::basic_istream::unget()

Turning a string that contains a equation into an integer [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I would like to be able to convert a string such as "(5+6)*6" and get the resulting integer from that equation. It is important that it starts out as a string.
You can use library fastmathparser for c++.
In link is example how use this library.
If you really want write alone this parser, I recomended use Shunting-yard algorithm

Need for undefined behaviour in c and c++? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Is there is any specific reason behind undefined behavior in C and C++?
Why are some features left undefined?
For some part at least, it was to allow a more efficient implementation.
A simple example: Function parameters. Their evaluation order in unspecifed, because some architectures could work better depending on how they made the calculations or the calling convention (registers, stack, etc.)