我在vs2010(win32控制台应用程序)中运行我的C代码.它被编译为C++应用程序.
#include "stdafx.h"
#define YES 1;
#define NO 0;
// function to determine if an integer is even
int isEven(int number)
{
int answer;
if ( number % 2 == 0)
answer = YES;
else
answer = NO;
return answer;
}
int main()
{
int isEven(int number);
if (isEven(17) == YES)
printf("yes ");
else
printf("no ");
if ( isEven(20) == YES)
printf("yes\n");
else
printf("no\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译错误如下.
p300.cpp(18): error C2181: illegal else without matching if
p300.cpp(30): error …Run Code Online (Sandbox Code Playgroud) 当我尝试使用RemoveChild()删除我的一些子元素时.但抛出异常.我在下面附上了我的代码.
nodeName = doc.SelectSingleNode("//Equipment//DataCollections//EnabledIDs//MyID[@id='" + attrValue + "']");
// Found the nodeName successfully druing run time.
doc.DocumentElement.RemoveChild(nodeName);
// faild to Remove the node
Run Code Online (Sandbox Code Playgroud)
显示以下错误:
An unhandled exception of type 'System.ArgumentException' occurred in System.Xml.dll
Additional information: The node to be removed is not a child of this node.
Run Code Online (Sandbox Code Playgroud)
如何删除节点?
[更新]
使用VS2005和.NET 2.0.
如何检测当前行中是否有(=)符号?谢谢.
$_ = $currentLine;
if (Include =)
{
# do some thing
}
else
{
# do another thing
}
Run Code Online (Sandbox Code Playgroud) 我用下面的脚本解析一个文本文件.
如何将数组数据插入MySQL表?
我已经学习了Perl MySQL DBI连接方法.我可以成功连接到本地MySQL数据库.我可以使用MySQL命令行创建表.
#!C:\Perl\bin\perl.exe
use strict;
use warnings;
while ( <DATA> ) {
my @rocks = split(/\s+/, $_);
foreach my $rock (@rocks) {
$rock = "\t$rock "; # put a tab in front of each element of @rocks
$rock .= "\n"; # put a newline on the end of each
print $rock ;
}
}
__DATA__
A B C D
E F G H
Run Code Online (Sandbox Code Playgroud)
我想要表浏览结果.
Item1 Item2 Itme3 Item4
A B C D
E F G … 假设我声明了一个isFind[]这样的数组,
bool[] isFind = new bool[5];
for (int i = 0; i < 5; ++i)
{
isFind[i] = init(); // initialize isFind[]
}
bool init();
{
...; // some code here
}
Run Code Online (Sandbox Code Playgroud)
是否有任何快速方法(较少的输入代码)来检测是否存在false元素isFind[]?我不想要for/foreach Loop数组列表中的每个元素.
[更新]
使用.NET 2.0.
快速方法(减少输入代码)
我已经完成了我的开发.但我不喜欢可执行应用程序的Windows图标.
如何用我最喜欢的一个替换默认的Windows图标?谢谢.
我做了这样的练习,如何通过XML :: Simple计算折叠成数组的XML元素的数量,这样我就不必对元素进行硬编码了?我计划使用代码来解析更大的xml文件.我不想通过手册来讨论这些元素.
我可以使用一些计数来代替幻数,有点像person.count或hobbie.length等.我知道,我可以在C#中方便地使用这种说法.
#!/usr/bin/perl -w
use strict;
use XML::Simple;
use Data::Dumper;
my $tree = XMLin('./t1.xml');
print Dumper($tree);
print "\n";
for (my $i = 0; $i < 2; $i++) # magic number '2'
{
print "$tree->{person}->[$i]->{first_name} $tree->{person}->[$i]->{last_name}\n";
print "\n";
for (my $j = 0; $j < 3; $j++) # magic number '3'
{
print $tree->{person}->[$i]->{hobbie}->[$j], "\n";
}
print "\n";
}
Run Code Online (Sandbox Code Playgroud)
出局:
could not find ParserDetails.ini in C:/Perl/site/lib/XML/SAX
$VAR1 = {
'person' => [
{
'hobbie' => …Run Code Online (Sandbox Code Playgroud) 我在如何打印哈希内容方面遇到了麻烦.
这段代码片段,
#!/usr/bin/perl -w
use strict;
use warnings;
my (%data, $keyword);
while (my $line = <DATA>){
next unless $line =~ /\S/;
chomp $line;
if ($line =~ /^Keyword/){
$keyword = $line;
}
else {
push @{$data{$keyword}}, $line;
}
}
# How to sort by keys using while loop?
while ( my ($k,$v) = each %data ) {
print "$k => $v\n";
}
# BTW, foreach loop sorting works.
#foreach my $key (sort (keys(%data))) {
# print "$key \t$data{$key}\n";
#}
__DATA__
Keyword1 …Run Code Online (Sandbox Code Playgroud) 我正在读一本Codeigniter书,它说的像这样,
在应用程序中使用关键字TRUE,FALSE和NULL时,应始终以大写字母书写它们.
为什么Codeigniter需要将所有关键字写成大写字母?
itemVal = "0";
res = int.TryParse(itemVal, out num);
if ((res == true) && (num.GetType() == typeof(byte)))
return true;
else
return false; // goes here when I debugging.
Run Code Online (Sandbox Code Playgroud)
为什么num.GetType() == typeof(byte)不回来true?
c# ×4
perl ×4
c#-2.0 ×2
xml ×2
arrays ×1
c++ ×1
codeigniter ×1
dbi ×1
frameworks ×1
function ×1
gettype ×1
hash ×1
icons ×1
if-statement ×1
insert ×1
loops ×1
php ×1
removechild ×1
windows ×1
xml-parsing ×1
xml-simple ×1