C ++比较一组值与给定的值(C++ comparing bunch of values with a given one)
我需要比较一个给定值与检索值。 我在代码中多次执行此操作。 我对它的外观并不满意,我正在寻求某种util功能。 有人写过一个吗?
我在比较的数值在编译时已知。
更新:我想摆脱容器,因为我知道确切数量的值(通常不超过3),我想与之比较。 每次将物品放入容器并不方便。
我不爱, 如果既不是因为它不明显就是“发现”。#include <algorithm> #include <string> #include <vector> std::string getValue1() { return "test"; } std::string getValue2() { return "the"; } std::string getValue3() { return "world"; } int main() { const std::string value = "the"; // simple if if ( value == getValue1() || value == getValue2() || value == getValue3() ) return 1; // using collections like vector, set std::vector<std::string> values; values.push_back( getValue1() ); values.push_back( getValue2() ); values.push_back( getValue3() ); if ( values.end() != std::find( values.begin(), values.end(), value ) ) return 1; // third option I'd use instead // return 0; }
I need to compare one given value with a retrieved values. I do this several times in the code. I am not satisfied with how it looks and I am seeking for a some sort of an util function. Anyone wrote one?
Number of values I am comparing with is known at the compile time.
Update: I'd like to get rid of containers as I know exact amount of values ( often not more then 3 ) I want to compare with. And it is not so convenient to put items to the container every time.
I don't love if neither because it is not obvious as "find".#include <algorithm> #include <string> #include <vector> std::string getValue1() { return "test"; } std::string getValue2() { return "the"; } std::string getValue3() { return "world"; } int main() { const std::string value = "the"; // simple if if ( value == getValue1() || value == getValue2() || value == getValue3() ) return 1; // using collections like vector, set std::vector<std::string> values; values.push_back( getValue1() ); values.push_back( getValue2() ); values.push_back( getValue3() ); if ( values.end() != std::find( values.begin(), values.end(), value ) ) return 1; // third option I'd use instead // return 0; }
原文:https://stackoverflow.com/questions/639496
最满意答案
万一其他人偶然发现同一问题:
- 您可以从旧框架运行这两个应用程序,即使使用.NET 4.5构建它也可以处理旧的MySQL连接器框架。 我还没有遇到.NET 4.5项目和为3.5构建的连接器之间的版本兼容性问题。
- 但是,您必须对旧框架进行新的引用 - 一旦卸载了新的MySQL连接器,依赖它的应用程序将停止运行,直到您安装另一个版本并引用该版本。
In case anyone else stumbles upon the same issue:
- You can run both applications off of the old framework, even if one is built with .NET 4.5 it can handle the old MySQL connector framework. I have yet to experience any issues with version compatibility between the .NET 4.5 project and the connector built for 3.5.
- You will have to make a new reference to the older framework, however - once the new MySQL connector is uninstalled your applications that rely on it will cease to function until you install another version and reference that one.
相关问答
更多-
我注意到你打开了连接,但是当你完成这些连接时你不会关闭它们。 我更喜欢在需要时打开连接的方法,而不是在尚未打开的情况下打开连接。 它们可能是陈旧的。 缓存连接字符串,但不是连接本身。 public static string ConnectionString {get;set;} public static bool InsertRecord(sql) { bool success = false; using (var con = new Connection(ConnectionStr ...
-
从Visual Studio运行MySQL Connector / C ++时崩溃(Crashes when running MySQL Connector/C++ from Visual Studio)[2022-10-18]
在@LyubomirVasilev的帮助下,我自己使用Visual Studio 11(2012)的设置编译了C ++ Connector。 用这里编译的替换其他lib和dll文件,之后就完美了。 有关此操作的信息可以在此处找到: http : //dev.mysql.com/doc/refman/5.1/en/connector-cpp-info.html With help from @LyubomirVasilev I compiled the C++ Connector on my own with ... -
为了后人或其他可能有一天遇到这个问题的人,这里有修复: 问题是本地计算机上的machine.config文件。 该文件没有正确的条目或任何混淆安装程序的内容。 我比较了机器上的machine.config文件,我可以在那里安装/卸载到失败的机器并设置与MySql不同的行,然后再次尝试卸载(或在W81上安装/卸载)。 成功! 这个问题真的让我陷入了困境。 安装程序不应该对该文件敏感。 错误消息有点错误,因为失败不是DLL而是machine.config。 For posterity sake or anyon ...
-
你可以从NuGet获得MySQL.Data: Install-Package MySql.Data 如果你必须直接从MySQL的网站上获取它, 它仍然存在 。 它实际上是您链接的页面上的顶级项目,它被称为“用于MySQL的ADO.NET驱动程序(Connector / NET)”。 You can get MySQL.Data from NuGet: Install-Package MySql.Data If you must get it from MySQL's website directly, ...
-
C#MySQL连接器[关闭](C# MySQL Connector [closed])[2023-09-01]
MySQL为C#提供.NET conector。 看到了 ! 您可以在非常简单的项目中使用它。 以下是使用ADO.NET和ODBC驱动程序的示例,以及如何直接使用它。 对于更复杂的项目,我强烈建议使用一些支持MySQL的OR映射器,如SubSonic或BLToolkit 。 MySQL provides .NET conector for C#. See this! You can use it in very simple projects. Here is an example of using it ... -
为了建立它,你需要有以下几点: 您需要安装MySQL服务器或MySQL C连接器 。 已经安装了Boost C ++库或者有它的源文件。 请注意,由于您只需要头文件,因此不需要增强增强功能。 安装CMake 。 安装CMake时,它会询问您是否希望它包含在PATH变量中,您应该选择“是”以便以后使用它更容易。 一旦有了所有三个可用,打开VS2012 x64 Native Tools命令提示符,并从MySQL C ++ Connector的源根目录,您需要发出以下命令: set MYSQL_DIR=c:\PR ...
-
万一其他人偶然发现同一问题: 您可以从旧框架运行这两个应用程序,即使使用.NET 4.5构建它也可以处理旧的MySQL连接器框架。 我还没有遇到.NET 4.5项目和为3.5构建的连接器之间的版本兼容性问题。 但是,您必须对旧框架进行新的引用 - 一旦卸载了新的MySQL连接器,依赖它的应用程序将停止运行,直到您安装另一个版本并引用该版本。 In case anyone else stumbles upon the same issue: You can run both applications off ...
-
链接MySQL C连接器?(Linking MySQL C connector?)[2023-12-09]
随机崩溃很可能与MySQL客户端库的多线程使用有关。 尝试这个 mysql_library_init(0, nullptr, nullptr); 在产生任何线程之前。 这里,来自MySQL文档的更具体的信息: 在非多线程环境中,可能会省略对mysql_library_init()的调用,因为mysql_init()会根据需要自动调用它。 但是,mysql_library_init()在多线程环境中不是线程安全的,因此调用mysql_library_init()的mysql_init()也不是。 您必须在产 ... -
MySQl和ASP.NET教程 也许这会有所帮助? MySQl and ASP.NET tutorial maybe this will help?
-
在Visual Studio或Visual C#中,删除对MySql.Data的引用,然后再次添加。 From within Visual Studio or Visual C#, remove the reference to MySql.Data and then add it again.