我正在尝试向我的 C++ 控制台应用程序添加一个图标,但是当我尝试编译以下代码时,我遇到了这些错误。第一个是我的 resources.rc,第二个文件是我的 main.cpp。
资源脚本:#ifndef RESOURCE_RC_INCLUDED
#define RESOURCE_RC_INCLUDED
MAINICON ICON "icon.ico"
#endif // RESOURCE_RC_INCLUDED`
C++ 源代码:
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
#include <windows.h>
#include <fstream>
#include "resources.rc"
using namespace std;
void SetWindow(int Width, int Height) {
_COORD coord;
coord.X = Width;
coord.Y = Height;
_SMALL_RECT Rect;
Rect.Top = 0;
Rect.Left = 0;
Rect.Bottom = Height - 1;
Rect.Right = Width - 1;
HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE); // Get Handle
SetConsoleScreenBufferSize(Handle, coord); // Set Buffer Size
SetConsoleWindowInfo(Handle, TRUE, &Rect); // Set Window Size
}
int main() {
SetWindow(105, 30);
SetConsoleTitle("Shima Command Line");
int x;
char file;
string name, cmd, selPrg, title;
string cmds[] = {"(help)", "(information)", "(exit)", "(tell me a joke)", "(open)", "(start)", "(talk dirty to me)", "(what is your favorite color)", "(what is your favourite colour)", "(cls)", "(clear)", "(title)"};
string jokes[] = {"If your cold you should sit in a corner, it's 90 degrees.", "Knock Knock\nWho's there?\nJustin.\nJustin who?\nJustin time for dinner.", "Why did the chicken cross the road?\nTo get to the other side.", "Jokes aren't really my thing.", "I don't know any good jokes.", "What do you call a cow that just had a baby?\nDe-calf-inated. You know like coffee.", "What do you get from a pampered cow?\nSpoiled milk.", "What do you get if you divide the circumference of a pumpkin by it's diameter?\nPumpkin Pi.", "Did you hear about the two antennas that got married?\nThe ceremony was long and boring, but the reception was great!"};
string prg[] = {"chrome", "opera", "notepad++", "notepad", "firefox", "ie", "codeblocks", "audacity", "cmd"};
cout << "What is your name?" << endl;
getline(cin, name);
cout << "Hello, " << name << ", my name is Shima Josei. " << endl;
x = 10;
do {
cout << "How may I help you?" << endl;
getline(cin, cmd);
if (cmd == cmds[0] || cmd == cmds[1] || cmd == cmds[2] || cmd == cmds[3] || cmd == cmds[4] || cmd == cmds[5] || cmd == cmds[6] || cmd == cmds[7] || cmd == cmds[8] || cmd == cmds[9] || cmd == cmds[10] || cmd == cmds[11]) {
if (cmd == cmds[0]) {
cout << "\n\nclear - Shima will clear all text." << endl;
cout << "cls - Shima will clear the screen." << endl;
cout << "exit - Shima will exit the program you are currently using." << endl;
cout << "help - Shima will display the help menu." << endl;
cout << "information - Shima will display information about her." << endl;
cout << "open - Shima will open the specified program." << endl;
cout << "start - Shima will start the specified program." << endl;
cout << "talk dirty to me - Shima will talk dirty to you." << endl;
cout << "tell me a joke - Shima will tell you a joke." << endl;
cout << "title - Shima will change the title." << endl;
cout << "what is your favorite color - Shima will display her favorite color." << endl;
cout << "what is your favourite colour - Shima will display her favourite colour in United Kingdom English.\n\n" << endl;
}
if (cmd == cmds[1]) {
cout << "\n\nShima Command Line was developed at\nGigaboy Web Designs by Adam Oates.\nCopyright (C) 2016 Shima Command Line. All rights reserved.\n\n" << endl;
}
if (cmd == cmds[2]) {
exit(0);
}
if (cmd == cmds[3]) {
srand(time(0));
cout << "\n\n" << jokes[rand() % 9] << "\n\n" << endl;
}
if (cmd == cmds[4] || cmd == cmds[5]) {
cout << "\n\nWhat program would you like to open?" << endl;
getline(cin, selPrg);
if (selPrg == prg[0] || selPrg == prg[1] || selPrg == prg[2] || selPrg == prg[3] || selPrg == prg[4] || selPrg == prg[5] || selPrg == prg[6] || selPrg == prg[7] || selPrg == prg[8]) {
if (selPrg == prg[0]) {
cout << "\n\nOpening Google Chrome..." << endl;
ShellExecute(NULL, "open", "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", NULL, NULL, SW_SHOWDEFAULT);
cout << "Successfully opened Google Chrome.\n\n" << endl;
}
if (selPrg == prg[1]) {
cout << "\n\nOpening Opera..." << endl;
ShellExecute(NULL, "open", "C:/Program Files/Opera/launcher.exe", NULL, NULL, SW_SHOWDEFAULT);
cout << "Successfully opened Opera.\n\n" << endl;
}
if (selPrg == prg[2]) {
cout << "\n\nOpening Notepad++..." << endl;
ShellExecute(NULL, "open", "C:/Program Files (x86)/Notepad++/notepad++.exe", NULL, NULL, SW_SHOWDEFAULT);
cout << "Successfully opened Notepad++.\n\n" << endl;
}
if (selPrg == prg[3]) {
cout << "\n\nOpening Notepad..." << endl;
ShellExecute(NULL, "open", "C:/Windows/notepad.exe", NULL, NULL, SW_SHOWDEFAULT);
cout << "Successfully opened Notepad.\n\n" << endl;
}
if (selPrg == prg[4]) {
cout << "\n\nOpening Mozilla Firefox..." << endl;
ShellExecute(NULL, "open", "C:/Program Files (x86)/Mozilla Firefox/firefox.exe", NULL, NULL, SW_SHOWDEFAULT);
cout << "Successfully opened Mozilla Firefox.\n\n" << endl;
}
if (selPrg == prg[5]) {
cout << "\n\nOpening Internet Explorer..." << endl;
ShellExecute(NULL, "open", "C:/Program Files/Internet Explorer/iexplorer.exe", NULL, NULL, SW_SHOWDEFAULT);
cout << "Successfully opened Internet Explorer.\n\n" << endl;
}
if (selPrg == prg[6]) {
cout << "\n\nOpening Code::Blocks..." << endl;
ShellExecute(NULL, "open", "C:/Program Files (x86)/CodeBlocks/codeblocks.exe", NULL, NULL, SW_SHOWDEFAULT);
cout << "Successfully opened Code::Blocks.\n\n" << endl;
}
if (selPrg == prg[7]) {
cout << "\n\nOpening Audacity..." << endl;
ShellExecute(NULL, "open", "C:/Program Files (x86)/Audacity/audacity.exe", NULL, NULL, SW_SHOWDEFAULT);
cout << "Successfully opened Audacity.\n\n" << endl;
}
if (selPrg == prg[8]) {
cout << "\n\nOpening Command Prompt..." << endl;
ShellExecute(NULL, "open", "C:/Windows/System32/cmd.exe", NULL, NULL, SW_SHOWDEFAULT);
cout << "Successfully opened Command Prompt.\n\n" << endl;
}
} else {
cout << "\n\nI'm sorry, " << name << ", but I don't recognize that program name." << endl;
}
}
if (cmd == cmds[6]) {
srand(time(0));
cout << "\n\nDirt, soil earth, rocks, and mud.\n\n" << endl;
}
if (cmd == cmds[7]) {
cout << "\n\nMy favorite color is... well I guess I've never had a favorite color.\n\n" << endl;
}
if (cmd == cmds[8]) {
cout << "\n\nMy favourite colour is... well I guess I have never had a favourite colour.\n\n" << endl;
}
if (cmd == cmds[9] || cmd == cmds[10]) {
system("CLS");
}
if (cmd == cmds[11]) {
cout << "\n\nWhat would you like the title to be?" << endl;
getline(cin, title);
SetConsoleTitle(title.c_str());
cout << "\n\n" << endl;
}
} else {
cout << "\n\nI'm sorry, " << name << ", but I don't understand that command.\n\n" << endl;
}
} while (x = 10);
return 0;
}
这些是我得到的错误。
||=== Build: Debug in Shima (compiler: GNU GCC Compiler) ===| C:\Users\Adam\Desktop\C++ Tutorial\Shima\resources.rc|4|error: 'MAINICON' does not name a type| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp||In function 'int main()':| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|35|error: 'string' was not declared in this scope| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|35|note: suggested alternative:| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stringfwd.h|65|note: 'std::string'| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|35|error: expected ';' before 'name'| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|36|error: expected ';' before 'cmds'| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|37|error: expected ';' before 'jokes'| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|38|error: expected ';' before 'prg'| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|39|error: 'cout' was not declared in this scope| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|39|note: suggested alternative:| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\iostream|62|note: 'std::cout'| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|39|error: 'endl' was not declared in this scope| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|39|note: suggested alternative:| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\ostream|562|note: 'std::endl'| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|40|error: 'cin' was not declared in this scope| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|40|note: suggested alternative:| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\iostream|61|note: 'std::cin'| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|40|error: 'name' was not declared in this scope| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|40|error: 'getline' was not declared in this scope| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|40|note: suggested alternative:| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\basic_string.h|2792|note: 'std::getline'| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|46|error: 'cmd' was not declared in this scope| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|47|error: 'cmds' was not declared in this scope| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|74|error: 'jokes' was not declared in this scope| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|79|error: 'selPrg' was not declared in this scope| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|80|error: 'prg' was not declared in this scope| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|158|error: 'title' was not declared in this scope| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|165|warning: suggest parentheses around assignment used as truth value [-Wparentheses]| C:\Users\Adam\Desktop\C++ Tutorial\Shima\main.cpp|34|warning: unused variable 'file' [-Wunused-variable]| ||=== Build failed: 17 error(s), 2 warning(s) (0 minute(s), 1 second(s)) ===|
最佳答案
在源文件中,您必须包含头文件 resource.h 而不是资源脚本 resource.rc。然后重新编译工程。
头文件:
#define MAINICON 101
Source C++ file:
#include <iostream>
#include ...
#include "resource.h"
using namespace std;
关于c++ - 如何将图标添加到您的 C++ 控制台应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35192511/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/