我想在Mac上的XCode中编写一个C++程序.我写了这个基本的测试它.当我构建时,我收到"Build Successful"消息.
但是,我无法运行它!如果我按下Command + R则没有任何反应.当我转到Project-> Run时,运行选项被禁用.
#include <iostream>
using namespace std;
int main()
{
cout << "helo" << endl;
}
Run Code Online (Sandbox Code Playgroud) 我在初始化结构数组时遇到问题.我不确定我是否做得对,因为我得到"从不兼容的指针类型初始化"和"从不兼容的指针类型分配".我在代码中添加了这些警告,当我尝试从结构中打印数据时,我只是得到垃圾,例如@@ ###
typedef struct
{
char* firstName;
char* lastName;
int day;
int month;
int year;
}student;
Run Code Online (Sandbox Code Playgroud)
//初始化数组
student** students = malloc(sizeof(student));
int x;
for(x = 0; x < numStudents; x++)
{
//here I get: "assignment from incompatible pointer type"
students[x] = (struct student*)malloc(sizeof(student));
}
int arrayIndex = 0;
Run Code Online (Sandbox Code Playgroud)
//添加struct
//create student struct
//here I get: "initialization from incompatible pointer type"
student* newStudent = {"john", "smith", 1, 12, 1983};
//add it to the array
students[arrayIndex] = newStudent;
arrayIndex++;
Run Code Online (Sandbox Code Playgroud) 好吧我正在创建一个ArrayAdapter并在我的Alert Dialog中使用它,因为我不想在SingleItemSelection对话框中显示默认的单选按钮.
相反,我想要更改所选项目的背景,然后当用户按下肯定按钮时,我将执行与所选项目相关的操作.
private void showAlertDialog()
{
final String[] options = getResources().getStringArray(R.array.dialog_options);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, options);
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
dialogBuilder.setTitle("My Dialog");
dialogBuilder.setAdapter(adapter, new OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Toast.makeText(getApplicationContext(), "item clicked at index " + which, Toast.LENGTH_LONG).show();
// Here I need to change the background color of the item selected and prevent the dialog from being dismissed
}
});
//String strOkay = getString(R.string.okay);
dialogBuilder.setPositiveButton("OK", null); // TODO
dialogBuilder.setNegativeButton("Cancel", null); // …Run Code Online (Sandbox Code Playgroud) 我无法将我的applet嵌入到网页中.我不认为我做得对.
*我的html文件与我的.class文件位于同一目录中
我的主要方法是在CardApp类中
这是我的HTML代码
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>TestJCardBet.html</title>
</head>
<body>
<applet codebase="" code="CardApp.class" height="400" width="500"></applet>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我在C中的链表的插入方法遇到了一些麻烦.它似乎只在列表的开头添加.我做的任何其他插入都失败了.而这个CodeBlocks调试器很难理解我仍然没有得到它.它永远不会给我价值,只有内存中的地址.无论如何这是我的功能.你有没有看到它失败的原因?
/* function to add a new node at the end of the list */
int addNodeBottom(int val, node *head){
//create new node
node *newNode = (node*)malloc(sizeof(node));
if(newNode == NULL){
fprintf(stderr, "Unable to allocate memory for new node\n");
exit(-1);
}
newNode->value = val;
//check for first insertion
if(head->next == NULL){
head->next = newNode;
printf("added at beginning\n");
}
else
{
//else loop through the list and find the last
//node, insert next to it
node *current = head;
while(current->next != NULL) …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Midlet应用程序.我发现自己需要经常缩放图像.这已经成为一个问题,因为有些手机很慢,缩放时间太长.
目前我正在使用Image.createRGBImage(int,int,int,boolean)来缩放图像.
我想知道你们中是否有人知道一种非常有效和快速的图像缩放方式.
注意:这是一个Midlet应用程序,因此只有JavaME可用,这意味着我无法访问完整Java版本中可用的其他库.
注意2:我的大部分缩放都是从小图像到大图像完成的,尽管我也缩小了图像.
我在计算文件中的单词数时遇到问题.我正在采取的方法是当我看到一个空间或一个新线时,我知道要算一个字.
问题是,如果我在段落之间有多行,那么我最终也将它们视为单词.如果你看一下readFile()方法,你可以看到我在做什么.
你能帮助我并指导我如何解决这个问题吗?
示例输入文件(包括空行):
word word word
word word
word word word
Run Code Online (Sandbox Code Playgroud) 我不确定我做错了什么,但我无法从控制台读取双重内容.读它因某种原因工作正常.我正在使用Xcode.
double n1;
// get input from the user
printf("Enter first number: ");
scanf("%f", &n1);
printf("%f", n1);
Run Code Online (Sandbox Code Playgroud)
无论我输入什么,这将始终打印0.
所以我使用相同的批处理脚本构建多个客户端.如果在构建一个错误时出现错误,则该过程将停止并继续下一个过程.因为屏幕上有很多输出而我正在做其他事情,大部分时间我都想念有一个构建错误.
如果出现错误,有没有办法停止执行以下任务,并显示弹出消息以引起我的注意?或者至少停止执行所以当我回到命令窗口时,我可以看到出现故障?
@echo off
if "%1"=="?" GOTO HELP
if NOT "%1"=="" set rev=%1
if NOT "%2"=="" set version=%2
@echo on
rem build one
call perl buildClient.pl -brandName="myBrand" -group="group1"
rem build two
call perl buildClient.pl -brandName="myBrand" -group="group2"
rem build three
call perl buildClient.pl -brandName="myBrand" -group="group3"
rem build four
call perl buildClient.pl -brandName="myBrand" -group="group4"
@echo off
goto EXIT
:HELP
cls
echo.
echo.
echo usage: buildbrand.bat [revision] [version] [group]
echo.
echo ? = this help screen
echo.
echo revision = build version
echo …Run Code Online (Sandbox Code Playgroud) 嗨我有一个使用结构的链表.现在我得到它在最后添加每个元素.但是,我想根据ID按排序顺序添加每个元素.该结构有两个元素:字符串名称和长ID.
node* temp = new node;
temp->name = nameRead;
temp->id = idRead;
//check if first item, if so add as head
if(head == NULL)
{
head = temp;
}
else
{
node* temp2 = head;
while(temp2->next != NULL)
{
temp2 = temp2->next;
}
temp2->next = temp;
}
Run Code Online (Sandbox Code Playgroud)