如何在Visual Studio 2010中运行C ++程序 [英] how to run C++ program in Visual Studio 2010

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

问题描述

我想在Visual Studio 2010中运行此C ++代码

I want to run this C++ code in visual studio 2010

#include<stdio.h>
#include<conio.h>
struct node
{
    int data;
    int count;
    struct node *right, *left;
}*root,*p,*q;

struct node *make(int y,int x)
{
    struct node *newnode;
    newnode=(struct node *)malloc(sizeof(struct node));
    newnode->data=y;
    newnode->count=x;
    newnode->right=newnode->left=NULL;
    return(newnode);
}

void left(struct node *r,int x)
{
    if(r->left!=NULL)
        printf("\n Invalid !");
    else
        r->left=make(x,y);
}

void right(struct node *r,int x)
{
    if(r->right!=NULL)
        printf("\n Invalid !");
    else
        r->right=make(x,y);
}


int postorder(struct node *r)
{
    int c=0;
    if(r!=NULL)
    {
        i=preorder(r->left);
        if(i!=0)
            ++c;
        i=preorder(r->right);
        if(i!=0)
            ++c;
        r->count=c1+c2;
        printf("\t %d \t %d",r->data,r->count);
    }
}


int i=0;
void main()
{
    int no1,no2;
    int choice;
    clrscr();
    printf("\n Enter the root:");
    scanf("%d",& no1);
    scanf("%d",& no2)
    root=make(no1,no2);
    p=root;
    while(1)
    {
        printf("\n Enter id and 0 number:");
        scanf("%d",& no1);
        scanf("%d",& no2);
        
        if(no1==-1)
            break;
        p=root;
        q=root;
        while(no1!=p->data && q!=NULL)
        {
            p=q;
            if(no1<p->data)
                q=p->left;
            else
                q=p->right;
        }
        if(no1<p->data)
        {
            printf("\n Left branch of %d is %d",p->data,no1);
            left(p,no1);
        }
        else
        {
            right(p,no1);
            printf("\n Right Branch of %d is %d",p->data,no1);
        }
    }
    while(1)
    {
        printf(" 3.Postorder Traversal \n 4.Exit");
        printf("\n Enter choice:");
        scanf("%d",&choice);
        switch(choice)
        {
            case 3 :postorder(root);
                break;
            case 4 :exit(0);
            default:printf("Error ! Invalid Choice ");
                break;
        }
        getch();
    }

}

推荐答案

启动VS2010
点击 File - New Project - Other Languages - Visual C++ - Win 32 - Win32 Console Application

输入名称,然后在下一个窗口中按Ok Finish .

然后用main 替换_tmain 内容,并添加其他变量和函数.

添加必要的标题,如果没有错误,它将运行.

祝您好运.
Start your VS2010
Click on File - New Project - Other Languages - Visual C++ - Win 32 - Win32 Console Application

Enter a name for it and press Ok and Finish in next window.

Then replace _tmain content with your main and also add you other variables and functions.

Add necessary headers and if there is no error it will run.

Good Luck.


首先,在此处发布任何其他代码片段之前,请礼貌地对它们进行正确格式化.缩进代码可能对您来说很容易阅读,但是对于大多数人(包括我自己)来说,它浪费了我们太多的时间.

要在VS中运行基本的C型程序,请创建一个新项目,选择C ++,然后选择Win32 Console应用程序.
您可能需要从_tmain例程调用Main函数,或将代码复制到其中.
First, before you post any further code fragments here, please have the politeness to format them properly. Unindented code may be easy for you top read, but it wastes far too much of our time for most people to be bothered, myself included.

To run a basic C-type program in VS, create a new project, select C++, and then Win32 Console application.
You may need to call your Main function from the _tmain routine, or copy the code into it.


此代码片段的第一个甚至无法在常规C ++编译器上运行.
示例:
First of this code fragment will not even run with a regular C++ compiler.
Example:
int postorder(struct node *r)
{
    int c=0;
    if(r!=NULL)
    {
        i=preorder(r->left);
        if(i!=0)
            ++c;
        i=preorder(r->right);
        if(i!=0)
            ++c;
        r->count=c1+c2; //Where is this c1 and c2 defined at least put the code fragment in context
        printf("\t %d \t %d",r->data,r->count);
    }
}



无论如何,我可以给您一些提示:

请执行以下步骤:
1.打开Visual Studio
2.创建新项目.
3.选择Visual c ++ win32控制台模板. (从左侧的创建新项目"对话框中选择Visual c ++,然后从右侧选择win32控制台)
4.键入您的项目/程序的名称.
5.您将打开一个文件,其内容如下:



Anyways I can give you some hints:

Follow these steps:
1.Open Visual Studio
2.Create new project.
3.Select the Visual c++ win32 console template. (From the create new project dialog in the left side choose visual c++ and then from the right side choose win32 console)
4.Type the name of your project/program.
5.You''ll get a file opened with contents like this:

#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}


6.从其中删除所有内容,但#include"stdafx.h"
7.复制整个代码.
8.Next,按照下面给出的下一个指令序列.


纠正常规编程错误后,您必须:
1.使用#include< malloc.h>使用malloc函数
2.用于使用clrscr();使用系统("cls");代替


6.Remove everything from this except #include "stdafx.h"
7.Copy your whole code.
8.Next follow the next sequence of instructions given below.


After correcting the general programming errors you have to:
1.Use #include<malloc.h> for using the malloc function
2.For using clrscr(); use system("cls"); instead


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

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