打开源文件 [英] Opening Source file

查看:94
本文介绍了打开源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我打开新项目的源文件时,我想将自己的文本写为默认文件!



#include< iostream> ;

使用命名空间std;

void main()

{



系统("暂停") )

}



这是我想要的数据每当我在视觉工作室的新项目中打开新的源文件时,都会在屏幕上看到!


TIA,


Sabeel Hussain


解决方案


我每次当我想将自己的文字写为默认文件时新项目的开源文件!



#include< iostream>

使用命名空间std ;

void main()

{



系统("暂停")

}



这是我希望在我的visual studio中的新项目中打开新源文件时我想在屏幕上看到的数据!




那么你真惭愧!这个代码在两个方面是错误的:



main()的返回必须是int,而不是void。这是由
C和C ++语言标准强制执行的。虽然VC ++仍然可以在没有b $ b b投诉的情况下接受无效,但它只支持旧的非标准代码。



你错过了一个半-colon在system()行的末尾。



至于更改默认代码模板,首先需要说明哪个是
你正在使用的VS的版本和版本。程序可能会有所不同。



对于某些背景知识,您应该阅读这些文章以及您的网络搜索引擎为您提供的任何其他与b $ b相关的链接。$


创建项目和项目模板





同时调查VS中的代码片段:



Visual C ++代码片段

https://msdn.microsoft.com/en-us/library/mt228278.aspx



- Wayne


I want to write my own text as default each time when i open source file of new project!

#include <iostream>
using namespace std;
void main()
{

system("pause")
}

This is the data i want to see on screen every time when i open new source file in new project in my visual studio!

TIA,

Sabeel Hussain

解决方案

I want to write my own text as default each time when i open source file of new project!

#include <iostream>
using namespace std;
void main()
{

system("pause")
}

This is the data i want to see on screen every time when i open new source file in new project in my visual studio!

Well shame on you then! This code is wrong in two respects:

The return from main() must be int, not void. That is mandated by the
C and C++ Language Standards. While VC++ may still accept void without
complaint, it is only to support old non-Standard code.

You're missing a semi-colon at the end of the system() line.

As to changing the default code template, you first need to state which
version and edition of VS you're using. Procedures may vary.

For some background, you should read over these articles and any other
related links that your Web search engine gives you.

Creating Project and Item Templates
https://msdn.microsoft.com/en-us/library/ms247121.aspx

Project Template in Visual Studio 2012
https://www.codeproject.com/articles/657765/project-template-in-visual-studio

Develop Faster with Customized Visual Studio Templates
https://visualstudiomagazine.com/articles/2012/08/20/visual-studio-custom-templates.aspx

Now in the case of a Win32 Console project, there is a relatively easy
"hack" that can be used - at leat with some versions of VS. That is to
change the code in the template supplied with the installation. For
example, using VS 2012 Express for Desktops:

(1) Navigate to the directory where the templates are found. e.g. -

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\VCWizards\AppWiz\Generic\Application\templates\1033

(2) Locate the file root.cpp and make a backup of it! Note that you will
need Administrator rights to make any changes in the Program Files directory.

(3) Open root.cpp in a text editor. Go to the very bottom of the file.
You should see code such as this:

[!if CONSOLE_APP]

int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}

[!endif]

Comment out or remove the existing code and add your own. e.g. -

[!if CONSOLE_APP]

//int _tmain(int argc, _TCHAR* argv[])
//{
//  return 0;
//}

#include <iostream>
using namespace std;
int main()
{

system("pause");
}

[!endif]

(4) Save it.

Then when a new Win32 Console Project is started, the default source
file/window will have:

As stated earlier, this is with VS 2012 so may not apply to other
versions such as 2015.

WARNING! Messing with Visual Studio's installation files can lead to a royal
muck-up if you aren't careful. That could result in the need to uninstall
and reinstall the complete product. Proceed with caution!

Judging from the code snippet you posted, I suspect that you are just
starting to learn C++ - if so, I strongly advise you to avoid messing
with things that you don't fully and clearly understand yet.

A safer alternative might be to use recorded macros, but support for
them varies with the different releases of VS. See this thread:

Can I record/play macros in Visual Studio 2012/2013/2015?
http://stackoverflow.com/questions/12062515/can-i-record-play-macros-in-visual-studio-2012-2013-2015

Also investigate Code Snippets in VS:

Visual C++ Code Snippets
https://msdn.microsoft.com/en-us/library/mt228278.aspx

- Wayne


这篇关于打开源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆