如何在Microsoft Visual Studio 2008中执行以下C ++程序 [英] how to execute the following C++ program in microsoft visual studio 2008

查看:78
本文介绍了如何在Microsoft Visual Studio 2008中执行以下C ++程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MS VISUAL STUDIO 2008在C ++中实现一些简单的程序.
下面列出的程序两次正确给出了输出,但是下一次我通过为一些变量和一些cout语句添加声明来修改它,如下所示:
int n1 = 1,n2 = 2,.... n16 = 16;
cout<< n1;
它没有给出任何输出,但是在程序代码之后给出了下面列出的错误.
以下是程序

I am trying to implement some simple programs in C++ using MS VISUAL STUDIO 2008.
The program listed below gave the output correctly twice,but the next time I modified it by adding declaration for some variables and some cout statements as
int n1=1,n2=2,....n16=16;
cout<<n1;
it did not give any output but gave the errors which are listed below, after the program code.
The following is the program

//jprojectname.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int id=0,
		nodeid1,
		nodeid2,
		nodeid3,
		nodeid4,
		nodeid5,
		nodeid6,
		nodeid7,
		nodeid8,
		nodeid9,
		nodeid10,
		nodeid11,
		nodeid12,
		nodeid13,
		nodeid14,
		nodeid15,
		nodeid16;
nodeid1=1;
nodeid2=2;
nodeid3=3;
nodeid4=4;
nodeid5=5;
nodeid6=6;
nodeid7=7;
nodeid8=8;
nodeid9=9;
nodeid10=10;
nodeid11=11;
nodeid12=12;
nodeid13=13;
nodeid14=14;
nodeid15=15;
nodeid16=16;
	cout<<"The LORD is good!\n\n";
	cout << "Hello World!\n";
	cout<<id;
	cout<<n1;
return 0;
}


以下是输出窗口的内容


The following is the output window contents

1>------ Build started: Project: jprojectname, Configuration: Debug Win32 ------
1>Compiling...
1>jprojectname.cpp
1>c:\documents and settings\students\my documents\visual studio 2008\projects\jprojectname\jprojectname\jprojectname.cpp(46) : error C2065: ''n1'' : undeclared identifier
1>Build log was saved at "file://c:\Documents and Settings\students\My Documents\Visual Studio 2008\Projects\jprojectname\jprojectname\Debug\BuildLog.htm"
1>jprojectname - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


您能否说出要成功执行porgram并获取输出需要执行的操作.

我已按照以下步骤创建程序:

1.我通过单击File-new-project-win32-win32console应用程序创建了一个新项目
-然后输入名称,单击确定
-然后我将t_main函数替换为最后给出的代码.
然后我保存了文件.然后按照以下步骤操作.单击调试菜单,在不进行调试的情况下调试启动
弹出消息询问
该项目已经过时了吗?您要构建它吗?
选择是,即可获得上面显示的内容.

[edit]已添加代码块,将我的内容作为纯文本..."选项已禁用-OriginalGriff [/edit]


Could you tell what needs to be done in order to succesfulyy execute the porgram and get the output.

I have followed the following steps to create my program:

1.I created a new project,by clicking File-new-project-win32-win32console application
-then entered the name-clicked ok
-then I replaced t_main funtion by the code given in the end.
Then I saved the file.Then I followed the following steps.I clicked on the debug menu,debug-start without debugging
A message popped up asking
This project is out of date Would you like to build it?
The contents displayed above were obtained after selecting yes.

[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]

推荐答案

错误消息不与您提供的源代码匹配.您确定同时报告了两者吗?
顺便说一句,在发布的代码中namespace被错误地写入(作为空白,即"na mespace").

[更新(因为问题已更新)]
您没有声明(根据需要)n1,并且编译器抱怨.
[/update]
The error messages doesn''t match with the source code you provided. Are you sure you reported exactly both?
By the way, in the posted code namespace is written wrongly (as a blank in, namely ''na mespace'').

[update (since the question was updated)]
You didn''t declare (as required) n1 and the compiler complains about.
[/update]


jprojectname.cpp(46) : error C2065: 'n1' : undeclared identifier


消息的这一部分说明了一切:文件和行所在的位置以及当前的问题. 未声明的标识符"是编译器发出的一条消息,告诉您它找到了无法识别的符号(在本例中为"n1").通常的原因是拼写错误,或者您忘记了使用该名称声明变量.修正拼写错误或插入声明即可.

在这种情况下,您显然最初使用了变量名"n1",但随后添加了完整的变量列表.为此,您决定给这些变量起一个更有意义的名称("nodeid"),但是却忘了改写试图将其发送到输出流的行.

在旁注中,为什么不只使用数组?


This part of the message says it all: the file and line where it is, and the problem at hand. ''undeclared identifier'' is a message by the compiler to tell you that it found a symbol (in this case ''n1'') which it couldn''t identify. The usual reason is either a typo, or you forgot to declare a variable by that name. Fix the typo or insert a declaration and you''re good.

In this particular case you apparently used the variable name ''n1'' originally, but then added a whole list of variables. In doing so you decided to give these variables a more meaningful name (''nodeid''), but forgot to adapt the line that tries to send it to the output stream.

On a sidenote, why don''t you just use an array?


声明n1然后再使用它....
Declare n1 and then use it....


这篇关于如何在Microsoft Visual Studio 2008中执行以下C ++程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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