有没有办法从cpp中包含一个objective-c标头?因为当我尝试从cpp .h文件#include"cocos2d.h"时,很多关于@和s的抱怨都出现了.
c ++文件可以包含像这样的obj-c标题吗?
我对C++有点新意,所以请耐心等待.我正在试图弄清楚我#defines和#includes我的项目到底在哪里.我有这样的事情:
main.h
#include "other.h"
#define MAX_GROUPS 100
struct Cat
{
int something[MAX_GROUPS];
}
Run Code Online (Sandbox Code Playgroud)
在other.h我还需要使用MAX_GROUPS,那么我也定义MAX_GROUPS在other.h这样的:
other.h
#define MAX_GROUPS 100
struct Other
{
int taco[MAX_GROUPS];
}
Run Code Online (Sandbox Code Playgroud)
问题是我定义了一个不止一个地方.我想把它们放在一起.
或者,我会重新加入main.h吗?
other.h
#include "main.h"
struct Other
{
int taco[MAX_GROUPS];
}
Run Code Online (Sandbox Code Playgroud)
这里的问题我认为它就像一个循环的依赖性东西.main.h包括other.h哪些包括main.h哪些包括other.h哪些包括...
设置项目的定义和包含的最佳方法是什么,以便将事物排序到其他包含的文件?通常的做法是在包含之前简单地完成所有定义吗?
我一直在使用PHP自定义CMS,直到最近才遇到任何问题.测试时,我注意到字符串已经开始出现在索引页面的顶部.在整个代码中使用一些die语句进行测试,似乎输出是在一个文件包含之间.
档案A.
<?php
if (!defined('IN_CMS'))
{
exit;
}
require(INCLUDE_PATH . '/pages/homepage/main.php');
?>
Run Code Online (Sandbox Code Playgroud)
文件B(包含文件)
<?php
if (!defined('IN_CMS'))
{
exit;
}
$db->sql_query("SELECT * FROM `" . DB_PREFIX . "categories` active = 1");
$cats = $db->sql_results();
$categories = array();
foreach($cats as $cat)
{
$cat_info = array(
'name' => $cat['name'],
'description' => $cat['description'],
'image' => $setting['site_url'] . '/thumbnails/' . $cat['image'],
);
$categories[] = $cat_info;
}
include theme('index');
?>
Run Code Online (Sandbox Code Playgroud)
我无法理解输出的来源,但它似乎介于两个文件之间.我已经ob_start()在文件A中的包含行之前添加,并且ob_end_clean()在包含文件的最开头添加并且输出没有显示,但是在两个文件中的任何地方都没有杂散输出.
如果它们位于不同的命名空间中,它们都被项目包含在内?由于两面性,我有一个问题就是包括它们......
我的理解总是通过#include <header.h>它在系统中查看包含目录,并且#include "header.h"它在本地目录中查找.但我只是查看python源代码,它使用该"header.h"方法在兄弟目录中定义标头.
所以py3k/Python/ast.c它确实如此#include "Python.h".但是Python.h在py3k/Include/Python.h
这是我从未见过的常见问题,没有参与任何真正的大型C项目吗?我怎么说,至少我的IDE,看看py3k/Include?
更新
我想出了如何告诉我的IDE包含它们,只是我是愚蠢和拼写错误.但我更感兴趣的是为什么""有效.是不是之间的不同""和<>?
现在正在C中创建一个服务器/客户端系统,我在客户端部分遇到了一些麻烦.从我所看到的,我需要使用sockaddr_in,以便我可以连接到服务器.但是,我每次都得到一个段错误.我相信sockaddr_in与它有关,正如评论它,它在程序后面的引用修复了segfault.
码:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
int main(int argc, char** argv)
{
int Csock;
int con;
char *data = 0;
char buf[101] = "";
struct sockaddr_in addr;
Csock = socket(AF_INET, SOCK_STREAM, 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(3435);
con = connect(Csock, (struct sockaddr*) &addr, sizeof(addr));
write(con, "Text", sizeof("Text"));
*data = read(con, buf, 100);
puts(data);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
可悲的是,我对C很陌生,所以这就像我能想到的那样......谁能告诉我一种消除段错的方法?
谢谢!
假设我要包含一个库:
#include <library.h>
Run Code Online (Sandbox Code Playgroud)
但我不确定它是否已安装在系统中。通常的方法是使用自动工具之类的工具。C ++中有更简单的方法吗?例如,在python中,您可以处理异常。
关于使用C++头文件和makefile文件,我有两个问题.我知道我有所有部件,我只是不确定如何将它们组合在一起.
我有以下文件:
main.cpp
Point.cpp
Point.h
Run Code Online (Sandbox Code Playgroud)
Point.h声明了我的简单Point对象,该定义位于Point.cpp文件中.然后在里面main()我想创建和使用Point对象.
我是否需要在Point.cpp文件中包含Point.h文件,或者是Makefile要关注的东西?另外,使用Point对象的main.cpp文件:我是否需要Point.cpp的include或者是否可以在Makefile中完成/可以完成?
这里的每个文件应包括什么以及我的Makefile应该是什么样的?
//从Linux平台独家工作//
我只是清理了我的.xml文件并外包了每个文件的页眉和页脚元素.之后我的projekt遇到错误,但只有8个文件中的2个.
旧代码:
<ImageView
android:layout_width = "wrap_content"
android:id = "@+id/ImageView01"
android:layout_height = "60dp"
android:src = "@drawable/logo"
android:scaleType = "fitXY">
Run Code Online (Sandbox Code Playgroud)
和新代码:
<include layout="@layout/header" /
Run Code Online (Sandbox Code Playgroud)
错误显示"找不到与给定名称匹配的资源('layout_below',值为'@id/searchRelativeLayout')
<LinearLayout
android:id = "@+id/SearchRelativeLayout"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:orientation = "horizontal"
android:layout_below = "@id/ImageView01"
android:gravity = "center"
android:layout_marginTop = "5dip"
android:paddingRight = "5dip"
android:paddingLeft = "5dip">
Run Code Online (Sandbox Code Playgroud)
我无法想象为什么它几乎适用于所有文件但不适用于这两种文件.它只是复制和粘贴,其余的都是一样的.
我已经包含了字符串,并且刚刚在头文件中的结构中调用了一个字符串变量.尽管在它之前调用了字符串,但我得到了字符串Origin和Destination City的'string not name a type'
//sortedListClass.h (a few lines of comments)
#include <string>
struct flightRec{
int flightnumber;
string Origin; //problem #1
string DestinationCity; // problem #2
float cost;
flightRec* ptr;
};
typedef flightRec* nodeptr;
#ifndef SORTEDLISTCLASS_H
#define SORTEDLISTCLASS_H
#include <iostream>
#include <cassert>
Run Code Online (Sandbox Code Playgroud)
sortedListClass.h:10:5:错误:'string'没有命名类型
sortedListClass.h:11:5:错误:'string'没有命名类型
我可能会问我做错了什么?