| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3905 人关注过本帖
标题:关于 Visual Studio 中,添加头文件不能运行问题!!
只看楼主 加入收藏
a75692074
Rank: 1
等 级:新手上路
威 望:1
帖 子:48
专家分:0
注 册:2018-7-20
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
关于 Visual Studio 中,添加头文件不能运行问题!!
废话不多说,我直接丢码过去了!!

头文件: coordin.h
程序代码:
#ifndef COORDIN_H_ 
#define COORDIN_H_
    
struct polar
{
    double distance; // distance 形式的起源
    double angle; // 方向从起源
};
struct rect
{
    double x; // 水平距离原点
    double y; // 垂直距离原点
};

// 原型
polar rec_to_polar(rect xypos);
void show_polar(polar dapos);

#endif // !COORDIN_H_ 


C++文件1: file1.cpp
程序代码:
#include <iostream>
#include "coordin.h" // 结构模板,函数原型
using namespace std;

int main()
{
    rect rplace; 
    polar pplace;

    cout << "Enter the x and y values: ";
    while (cin >> rplace.x >> rplace.y) // 熟练使用 cin
    {
        pplace = rec_to_polar(rplace);
        show_polar(pplace);
        cout << "Next two numbers (q to quit): ";
    }
    cout << "Bye!\n";
    return 0;
}


C++文件2: file2.cpp
程序代码:
#include <iostream>
#include <cmath>
#include "coordin.h" // 结构模板,函数原型
using namespace std;


// 将直角坐标转换为 polar 坐标
polar rect_to_polar(rect xypos)
{
    polar answer;

    answer.distance =
        sqrt(xypos.x * xypos.x + xypos.y * xypos.y);
    answer.angle = atan2(xypos.y, xypos.x);
    return answer; // 返回一个 polar 结构
}

// 显示 polar 坐标,将角度转换成角度
void show_polar(polar dapos)
{
    const double Rad_to_deg = 57.29577951;

    cout << "distance = " << dapos.distance;
    cout << ", angle = " << dapos.angle * Rad_to_deg;
    cout << " degrees\n";
}


编译器提示:
#include 语句中指定用 /Yc文件名源代码文件中找不到命令行选项


怎么解决呢??
搜索更多相关主题的帖子: 头文件 double include cout answer 
2019-01-31 17:00
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:7 
/Yc (Create Precompiled Header File)
2019-01-31 19:57
cstdio
Rank: 5Rank: 5
来 自:上海市静安区
等 级:贵宾
威 望:15
帖 子:97
专家分:44
注 册:2018-5-30
收藏
得分:7 
file2.cpp 应该改为coordin.cpp
要么file1.cpp中的#include"coordin.cpp改为#include"file2.cpp"

import random
i=random.randint(100,100000)
print i
2019-02-01 08:03
ZJYTY
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:4
帖 子:92
专家分:700
注 册:2018-12-20
收藏
得分:7 
main函数为标准C/C++的程序入口,编译器会先找到该函数所在的文件。假定编译程序编译myproj.c(其中含main())时,发现它include了mylib.h(其中声明了函数void test()),那么此时编译器将按照事先设定的路径(Include路径列表及代码文件所在的路径)查找与之同名的实现文件(扩展名为.cpp或.c,此例中为mylib.c),如果找到该文件,并在其中找到该函数(此例中为void test())的实现代码,则继续编译;如果在指定目录找不到实现文件,或者在该文件及后续的各include文件中未找到实现代码,则返回一个编译错误。

-------------------------------若有不当之处,敬请谅解-------------------------------
2019-02-01 09:51
快速回复:关于 Visual Studio 中,添加头文件不能运行问题!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016666 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved