用头文件开始一个新项目
Starting a new project with just a header file
我正在上c++课,并得到了我的第一个项目。在课堂上,教授只讲句法、语法等。他从不谈论如何使用Visual Studio。他给我们发了一个没有任何解释的头文件,并希望我们在项目中使用它。我不太确定如何开始使用这个文件。我试着创建一个空的Visual c++项目,添加这个文件并运行它,但对于一个,到处都有红色下划线错误,两个,VS说它找不到可执行文件。如果有人可以帮助我获得VS和/或我的项目设置,我可以负责制作程序(刚刚完成了在Java中编写相同的程序)。
这是他发给我们的头文件。从外表来看,他有点邋遢。
#pragma once
namespace control2 {
using namespace System;
using namespace System::IO; // added by Zhang
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
// added by Zhang
StreamReader ^sr = gcnew StreamReader("control.txt");
this->choice=Int32::Parse(sr->ReadLine());
sr->Close();
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
int choice;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->SuspendLayout();
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 266);
this->Name = L"Form1";
this->Text = L"CS351";
this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::Form1_Paint);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void Form1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
Graphics ^g = e->Graphics;
// g->Clear(BackColor);
// g->Clear(Color::Red);
for ( int y = 0; y < 10; y++ ) {
// pick the shape based on the user's choice
switch ( choice )
{
case 1: // draw rectangles
g->DrawRectangle(Pens::Black, 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10 );
break;
case 2: // draw ovals
// g->DrawEllipse(Pens::Black, 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10 );
g->DrawArc(Pens::Black, 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10, 0, 360 );
break;
case 3: // fill rectangles
g->FillRectangle(Brushes::Red, 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10 );
break;
case 4: // fill ovals
// g->FillEllipse(gcnew SolidBrush(Color::Red), 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10 );
g->FillPie(gcnew SolidBrush(Color::Red), 10 + i * 10, 10 + i * 10, 50 + i * 10, 50 + i * 10, 0, 360 );
break;
default: // draw lines
g->DrawLine(Pens::Black, 10 + i * 10, 60 + i * 20, 60 + i * 20, 10 + i * 10 );
break;
} // end switch
} // end for
choice=(choice+1)%5;
}
};
}
啊…编译指示…不管怎样…
如果你打开VS,然后进入file,你会发现新的项目选项。我假设这是一个Windows窗体应用程序。所以,选择新项目,在语言下选择c++,然后Windows窗体应用程序。当这一切都设置好后,转到文件->保存所有并将其放在一个目录中。现在把教授给你的文件和其他代码文件放在那个目录里。回到您的项目,在解决方案资源管理器下,右键单击头文件,添加,添加现有的,并选择您的头文件。这应该足够让你开始了!
相关文章:
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 当一个新对象被分配到它的地址时,对象是否必须被销毁
- 如何使用CLion在Mac上创建一个新的.txt文件
- 将一个 QWidget 链接到另一个新创建的 QWidget
- 使用Visual Studio在虚幻引擎中创建一个新的类c ++给了我太多的错误
- C++,每个循环初始化一个新的静态变量
- 如果我们不创建一个新节点并使用指针插入数据并建立链接(在链表中)怎么办?
- 在SFML(C++)中启动一个新窗口
- 有没有一种方法可以从函数中返回一个新对象或对现有对象的引用
- r-在Rcpp和C++之间转换矢量(使用Rcpp::as或Rcpp:::wrap)是否会创建一个新的矢量并复制元素
- 如何编译和运行一个新的 C++ Actor 框架项目?
- 在Clion的新窗口中创建一个新项目
- TensorFlow,Android Studio和Bazel:建立一个新项目
- 为什么每当我创建一个新的C++项目时,Eclipse都默认为调试模式
- 用头文件开始一个新项目
- 如何改变默认#包括在Visual Studio 2013(c++)中,当我创建一个新项目
- c++ /OpenGL -开始一个新项目
- 创建一个新的Cocos2d-x项目已超过200亿!如何创建更简单的模板
- 使用 /Command 选项从命令行为 Visual Studio C++ 项目创建一个新文件
- 当我开始一个新项目时,Visual Studio 2012会忘记SDL配置