当柳上原的风吹向天际的时候...

真正的快乐来源于创造

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  368 Posts :: 1 Stories :: 201 Comments :: 0 Trackbacks

#

    FROM:

http://blog.csdn.net/pangdingshan/article/details/7198760



   系统环境:windows 7 旗舰版

      软件版本:IBM DB2数据库(DB2_ESE_97_Win_x86)

      准备工作:关闭防火墙及杀软等安全防护软件

     本文是事后整理的,可以在循序上有些乱,有些步奏也是省略的,省略的都是选择默认选项

1.   运行安装目录下的  setup.exe 程序,点击“下一步”

2.    选择“我接受许可证协议中的全部条款”,点击“下一步”

3.  根据自己需求选择安装方式,我选择“典型安装”,点击“下一步”

4.   选择“在此计算机上安装DB2Enterprise Server Edition ” ,点击“下一步”

5.    更改安装路径,点击“下一步”

6.    默认选项,点击“下一步”

 

7.    设置密码,点击“下一步”

 

8. 不勾选“设置DB2服务器以发送通知”,点击“下一步”

9.    勾选“启动操作系统安全性”,点击“下一步”

10.   勾选“准备DB2工具目录”,点击“下一步”

 

11.  点击“下一步”,进行安装

  安装成功后会有提示



我安装的时候出现以下问题:
posted @ 2013-07-14 00:11 何杨 阅读(314) | 评论 (0)编辑 收藏

http://www.cnblogs.com/mingmingruyuedlut/archive/2011/11/04/2235630.html


1:

Internet Information Services 7.5

Error Summary

HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information
Module IIS Web Core
Notification Unknown
Handler Not yet determined
Error Code 0x80070005
Config Error Cannot read configuration file due to insufficient permissions
Config File \\?\C:\Users\EricSun\Documents\Visual Studio 2010\WebSites\SSOAuthWebSite1\web.config
Requested URL http://10.2.5.153:10001/
Physical Path  
Logon Method Not yet determined
Logon User Not yet determined
Config Source
 -1:     0:  
Links and More InformationThis error occurs when there is a problem reading the configuration file for the Web server or Web application. In some cases, the event logs may contain more information about what caused this error.

View more information »

 

Cause:1) 没有向iis中注册.net framework(引起的原因之一:先安装了.net framework,后安装的iis)

    2) 没有对IIS中所配置的site有足够的操作权限(Modify权限)

Solution:

    1) 到C:\Windows\Microsoft.NET\Framework64\v2.0.50727下,

      用命令向iis中重新注册一下.net framework:aspnet_regiis -i

    2) IIS Manager --> Sites --> 相应的site --> 点击右键 --> Edit Permissions --> Security --> Group or user names --> Edit --> Add --> 添加赋予Full Control权限(实质上带有Modify的权限就可以)的Everyone用户

 


2:

Server Error in '/' Application.


Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.

Source Error:

Line 9:  	</connectionStrings> Line 10: 	<system.web> Line 11: 		<compilation debug="true" targetFramework="4.0"/> Line 12: 		<authentication mode="Forms"> Line 13: 			<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>


Source File: C:\Users\EricSun\Documents\Visual Studio 2010\WebSites\SSOAuthWebSite1\web.config    Line: 11


Version Information: Microsoft .NET Framework Version:2.0.50727.4963; ASP.NET Version:2.0.50727.4955

 

Cause:当前程序所运行的.NET Framework版本与IIS中相应site所设置的.NET Framework版本不相同

Solution:启动IIS Manager --> Application Pools --> 选择相应的Name(site) --> 点击右键 --> Advanced Settings --> (General).NET Framwork Version --> 由2.0更改到4.0即可

 

3:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2ae25944\4afe0277\App_global.asax.ke894tgr.dll' -- 'Access is denied. '

Source Error:

 
[No relevant source lines]


Source File:    Line: 0


Show Detailed Compiler Output:

c:\windows\system32\inetsrv> "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" /t:library /utf8output /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Activities.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" /out:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2ae25944\4afe0277\App_global.asax.ke894tgr.dll" /debug- /optimize+ /w:4 /nowarn:1659;1699;1701 /warnaserror-  "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2ae25944\4afe0277\App_global.asax.ke894tgr.0.cs" "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2ae25944\4afe0277\App_global.asax.ke894tgr.1.cs"   Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1 Copyright (C) Microsoft Corporation. All rights reserved.  error CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2ae25944\4afe0277\App_global.asax.ke894tgr.dll' -- 'Access is denied. ' 




Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

 

Cause:对Windows下的temp文件夹缺少操作权限

Solution: 将Windows下的temp文件夹 --> properties --> security --> create owner --> add --> 添加赋予Full Control权限的Everyone用户

 

4:

Server Error in '/' Application.


Login failed for user 'IIS APPPOOL\SSO1'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IIS APPPOOL\SSO1'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[SqlException (0x80131904): Login failed for user 'IIS APPPOOL\SSO1'.]    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +6333696    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412    System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363    System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +53    System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +6348638    System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +6348553    System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +352    System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +831    System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +49    System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +6350358    System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +78    System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +1938    System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +89    System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6353246    System.Data.SqlClient.SqlConnection.Open() +300    System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +150    System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +4679471    System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Boolean updateLastLoginActivityDate, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved, DateTime& lastLoginDate, DateTime& lastActivityDate) +3720151    System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +189    System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password) +202    System.Web.UI.WebControls.Login.AuthenticateUsingMembershipProvider(AuthenticateEventArgs e) +225    System.Web.UI.WebControls.Login.AttemptLogin() +166    System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +93    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +52    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707 



Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

 

Cause:IIS中的Application pool中相应site的Identity类型错误

Solution: IIS Manager --> Application Pools --> 找到相应的site --> 左键选择Advanced Settings --> 将Process Model中的Identity类型换成LocalSystem

此问题(4)的解决方法可以详 见:http://blogs.microsoft.co.il/blogs/shlomo/archive/2009/11/09/system- data-sqlclient-sqlexception-login-failed-for-user-iis-apppool-defaultapppool.aspx

 

5:

 

Server Error in '/' Application.
--------------------------------------------------------------------------------

 

Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

 

Exception Details: System.TypeLoadException: Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

 

Source Error:

 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

 

Stack Trace:

 


[TypeLoadException: Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.]
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName) +314
System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +95
System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +124
System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +76

 

[ConfigurationErrorsException: Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.]
System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +11355388
System.Web.Configuration.Common.ModulesEntry.SecureGetType(String typeName, String propertyName, ConfigurationElement configElement) +69
System.Web.Configuration.Common.ModulesEntry..ctor(String name, String typeName, String propertyName, ConfigurationElement configElement) +62
System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +301
System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +1332
Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleReflectionUtil.GetIntegratedModuleCollection(HttpApplication target, IntPtr appContext) +34
Microsoft.Web.Infrastructure.DynamicModuleHelper.CriticalStatics.Init(HttpApplication context) +264
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +546
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +325
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375

 

[HttpException (0x80004005): Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11524352
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4782309

 

 

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

 

 

 

Cause:.Net Framework4先安装,IIS后安装,导致.Net Framework4.0没有注册到IIS中

 

Solution: 在Windows的文件夹里找到一个安装程序,在CMD里执行,具体如下:

      C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -iru
      显示如下:
      Start installing ASP.NET (4.0.30319).
      ..........
      Finished installing ASP.NET (4.0.30319).
      这样就可以了。
 
此问题的更详细的原因请看: http://msdn.microsoft.com/zh-cn/library/k6h9cz8h.aspx
posted @ 2013-07-12 13:22 何杨 阅读(1469) | 评论 (0)编辑 收藏

char* HcC21PrintPres::getStringFromDouble(double d){
    char  sbuf2[256];

    sprintf(sbuf2,"%.3f",d);// 保留位数自己可调

    for(;sbuf2[strlen(sbuf2) - 1] == '0';){
        sbuf2[strlen(sbuf2) - 1] = '\0';
        if(sbuf2[strlen(sbuf2) - 1] == '.'){
            sbuf2[strlen(sbuf2) - 1] = '\0';
            break;
        }
    }

    return sbuf2;
}
这种写法还是挺有意思的.
posted @ 2013-07-11 10:33 何杨 阅读(317) | 评论 (0)编辑 收藏

http://blog.csdn.net/masikkk/article/details/5634886

在将各种类型的数据构造成字符串时,sprintf 的强大功能很少会让你失望。由于sprintf 跟printf 在用法上几乎一样,只是打印的目的地不同而已,前者打印到字符串中,后者则直接在命令行上输出。这也导致sprintf 比printf 有用得多。
  sprintf 是个变参函数,定义如下:
  int sprintf( char *buffer, const char *format [, argument] ... );
  除了前两个参数类型固定外,后面可以接任意多个参数。而它的精华,显然就在第二个参数:

  (1)格式化字符串上。

  printf 和sprintf 都使用格式化字符串来指定串的格式,在格式串内部使用一些以“%”开头的格式说明符(format specifications)来占据一个位置,在后边的变参列表中提供相应的变量,最终函数就会用相应位置的变量来替代那个说明符,产生一个调用者想要 的字符串。
  格式化数字字符串
  sprintf 最常见的应用之一莫过于把整数打印到字符串中,所以,spritnf 在大多数场合可以替代itoa。
  如:
  //把整数123 打印成一个字符串保存在s 中。
  sprintf(s, "%d", 123); //产生"123"
  可以指定宽度,不足的左边补空格:
  sprintf(s, "%8d%8d", 123, 4567); //产生:" 123 4567"
  当然也可以左对齐:
  sprintf(s, "%-8d%8d", 123, 4567); //产生:"123 4567"
  也可以按照16 进制打印:
  sprintf(s, "%8x", 4567); //小写16 进制,宽度占8 个位置,右对齐
  sprintf(s, "%-8X", 4568); //大写16 进制,宽度占8 个位置,左对齐
  这样,一个整数的16 进制字符串就很容易得到,但我们在打印16 进制内容时,通常想要一种左边补0 的等宽格式,那该怎么做呢?很简单,在表示宽度的数字前面加个0 就可以了。
  sprintf(s, "%08X", 4567); //产生:"000011D7"
  上面以”%d”进行的10 进制打印同样也可以使用这种左边补0 的方式。
  这里要注意一个符号扩展的问题:比如,假如我们想打印短整数(short)-1 的内存16 进制表示形式,在Win32 平台上,一个short 型占2 个字节,所以我们自然希望用4 个16 进制数字来打印它:
  short si = -1;
  sprintf(s, "%04X", si);
  产生“FFFFFFFF”,怎么回事?因为spritnf 是个变参函数,除了前面两个参数之外,后面的参数都不是类型安全的,函数更没有办法仅仅通过一个“%X”就能得知当初函数调用前参数压栈时被压进来的到底 是个4 字节的整数还是个2 字节的短整数,所以采取了统一4 字节的处理方式,导致参数压栈时做了符号扩展,扩展成了32 位的整数-1,打印时4 个位置不够了,就把32 位整数-1 的8 位16 进制都打印出来了。
  如果你想看si 的本来面目,那么就应该让编译器做0 扩展而不是符号扩展(扩展时二进制左边补0 而不是补符号位):
  sprintf(s, "%04X", (unsigned short)si);
  就可以了。或者:
  unsigned short si = -1;
  sprintf(s, "%04X", si);
  sprintf 和printf 还可以按8 进制打印整数字符串,使用”%o”。注意8 进制和16 进制都不会打
  印出负数,都是无符号的,实际上也就是变量的内部编码的直接的16 进制或8 进制表示。
  控制浮点数打印格式
  浮点数的打印和格式控制是sprintf 的又一大常用功能,浮点数使用格式符”%f”控制,默认保
  留小数点后6 位数字,比如:
  sprintf(s, "%f", 3.1415926); //产生"3.141593"
  但有时我们希望自己控制打印的宽度和小数位数,这时就应该使用:”%m.nf”格式,其中m 表
  示打印的宽度,n 表示小数点后的位数。比如:
  sprintf(s, "%10.3f", 3.1415626); //产生:" 3.142"
  sprintf(s, "%-10.3f", 3.1415626); //产生:"3.142 "
  sprintf(s, "%.3f", 3.1415626); //不指定总宽度,产生:"3.142"
  注意一个问题,你猜
  int i = 100;
  sprintf(s, "%.2f", i);
  会打出什么东东来?“100.00”?对吗?自己试试就知道了,同时也试试下面这个:
  sprintf(s, "%.2f", (double)i);
  第一个打出来的肯定不是正确结果,原因跟前面提到的一样,参数压栈时调用者并不知道跟i相对应的格式控制符是个”%f”。而函数执行时函数本身则并不 知道当年被压入栈里的是个整数,于是可怜的保存整数i 的那4 个字节就被不由分说地强行作为浮点数格式来解释了,整个乱套了。不过,如果有人有兴趣使用手工编码一个浮点数,那么倒可以使用这种方法来检验一下你手工编 排的结果是否正确。
  

    (2)字符/Ascii 码对照

  我们知道,在C/C++语言中,char 也是一种普通的scalable 类型,除了字长之外,它与short,
  int,long 这些类型没有本质区别,只不过被大家习惯用来表示字符和字符串而已。(或许当年该把
  这个类型叫做“byte”,然后现在就可以根据实际情况,使用byte 或short 来把char 通过typedef 定义出来,这样更合适些)于是,使用”%d”或者”%x”打印一个字符,便能得出它的10 进制或16 进制的ASCII 码;反过来,使用”%c”打印一个整数,便可以看到它所对应的ASCII 字符。以下程序段把所有可见字符的ASCII 码对照表打印到屏幕上(这里采用printf,注意”#”与”%X”合用时自动为16 进制数增加”0X”前缀):
  for(int i = 32; i < 127; i++) {
  printf("[ %c ]: %3d 0x%#04X/n", i, i, i);
  }


  (3)连接字符串

  sprintf 的格式控制串中既然可以插入各种东西,并最终把它们“连成一串”,自然也就能够连
  接字符串,从而在许多场合可以替代strcat,但sprintf 能够一次连接多个字符串(自然也可以同时
  在它们中间插入别的内容,总之非常灵活)。比如:
  char* who = "I";
  char* whom = "CSDN";
  sprintf(s, "%s love %s.", who, whom); //产生:"I love CSDN. "
  strcat 只能连接字符串(一段以’’结尾的字符数组或叫做字符缓冲,null-terminated-string),但有时我们有两段字符缓冲区,他们并不是以 ’’结尾。比如许多从第三方库函数中返回的字符数组,从硬件或者网络传输中读进来的字符流,它们未必每一段字符序列后面都有个相应的’’来结尾。如果直接 连接,不管是sprintf 还是strcat 肯定会导致非法内存操作,而strncat 也至少要求第一个参数是个null-terminated-string,那该怎么办呢?我们自然会想起前面介绍打印整数和浮点数时可以指定宽度,字符串 也一样的。比如:
  char a1[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G'};
  char a2[] = {'H', 'I', 'J', 'K', 'L', 'M', 'N'};
  如果:
  sprintf(s, "%s%s", a1, a2); //Don't do that!
  十有八九要出问题了。是否可以改成:
  sprintf(s, "%7s%7s", a1, a2);
  也没好到哪儿去,正确的应该是:
  sprintf(s, "%.7s%.7s", a1, a2);//产生:"ABCDEFGHIJKLMN"
  这可以类比打印浮点数的”%m.nf”,在”%m.ns”中,m 表示占用宽度(字符串长度不足时补空格,超出了则按照实际宽度打印),n 才表示从相应的字符串中最多取用的字符数。通常在打印字符串时m 没什么大用,还是点号后面的n 用的多。自然,也可以前后都只取部分字符:
  sprintf(s, "%.6s%.5s", a1, a2);//产生:"ABCDEFHIJKL"
  在许多时候,我们或许还希望这些格式控制符中用以指定长度信息的数字是动态的,而不是静态指定的,因为许多时候,程序要到运行时才会清楚到底需要取字 符数组中的几个字符,这种动态的宽度/精度设置功能在sprintf 的实现中也被考虑到了,sprintf 采用”*”来占用一个本来需要一个指定宽度或精度的常数数字的位置,同样,而实际的宽度或精度就可以和其它被打印的变量一样被提供出来,于是,上面的例子 可以变成:
  sprintf(s, "%.*s%.*s", 7, a1, 7, a2);
  或者:
  sprintf(s, "%.*s%.*s", sizeof(a1), a1, sizeof(a2), a2);
  实际上,前面介绍的打印字符、整数、浮点数等都可以动态指定那些常量值,比如:
  sprintf(s, "%-*d", 4, 'A'); //产生"65 "
  sprintf(s, "%#0*X", 8, 128); //产生"0X000080","#"产生0X
  sprintf(s, "%*.*f", 10, 2, 3.1415926); //产生" 3.14"


  (4)打印地址信息

  有时调试程序时,我们可能想查看某些变量或者成员的地址,由于地址或者指针也不过是个32 位的数,你完全可以使用打印无符号整数的”%u”把他们打印出来:
  sprintf(s, "%u", &i);
  不过通常人们还是喜欢使用16 进制而不是10 进制来显示一个地址:
  sprintf(s, "%08X", &i);
  然而,这些都是间接的方法,对于地址打印,sprintf 提供了专门的”%p”:
  sprintf(s, "%p", &i);
  我觉得它实际上就相当于:
  sprintf(s, "%0*x", 2 * sizeof(void *), &i);


  (5)利用sprintf 的返回值

  较少有人注意printf/sprintf 函数的返回值,但有时它却是有用的,spritnf 返回了本次函数调用
  最终打印到字符缓冲区中的字符数目。也就是说每当一次sprinf 调用结束以后,你无须再调用一次
  strlen 便已经知道了结果字符串的长度。如:
  int len = sprintf(s, "%d", i);
  对于正整数来说,len 便等于整数i 的10 进制位数。
  下面的是个完整的例子,产生10 个[0, 100)之间的随机数,并将他们打印到一个字符数组s 中,
  以逗号分隔开。
  #include
  #include
  #include
  int main() {
  srand(time(0));
  char s[64];
  int offset = 0;
  for(int i = 0; i < 10; i++) {
  offset += sprintf(s + offset, "%d,", rand() % 100);
  }
  s[offset - 1] = '/n';//将最后一个逗号换成换行符。
  printf(s);
  return 0;
  }
  设想当你从数据库中取出一条记录,然后希望把他们的各个字段按照某种规则连接成一个字
  符串时,就可以使用这种方法,从理论上讲,他应该比不断的strcat 效率高,因为strcat 每次调用
  都需要先找到最后的那个’’的位置,而在上面给出的例子中,我们每次都利用sprintf 返回值把这
  个位置直接记下来了。
  使用sprintf 的常见问题
  sprintf 是个变参函数,使用时经常出问题,而且只要出问题通常就是能导致程序崩溃的内存访
  问错误,但好在由sprintf 误用导致的问题虽然严重,却很容易找出,无非就是那么几种情况,通
  常用眼睛再把出错的代码多看几眼就看出来了。
  ?? 缓冲区溢出
  第一个参数的长度太短了,没的说,给个大点的地方吧。当然也可能是后面的参数的问
  题,建议变参对应一定要细心,而打印字符串时,尽量使用”%.ns”的形式指定最大字符数。
  ?? 忘记了第一个参数
  低级得不能再低级问题,用printf 用得太惯了。//偶就常犯。:。(
  ?? 变参对应出问题
  通常是忘记了提供对应某个格式符的变参,导致以后的参数统统错位,检查检查吧。尤
  其是对应”*”的那些参数,都提供了吗?不要把一个整数对应一个”%s”,编译器会觉得你
  欺她太甚了(编译器是obj 和exe 的妈妈,应该是个女的,:P)。
  strftime
  sprnitf 还有个不错的表妹:strftime,专门用于格式化时间字符串的,用法跟她表哥很像,也
  是一大堆格式控制符,只是毕竟小姑娘家心细,她还要调用者指定缓冲区的最大长度,可能是为
  了在出现问题时可以推卸责任吧。这里举个例子:
  time_t t = time(0);
  //产生"YYYY-MM-DD hh:mm:ss"格式的字符串。
  char s[32];
  strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", localtime(&t));
  sprintf 在MFC 中也能找到他的知音:CString::Format,strftime 在MFC 中自然也有她的同道:
  CTime::Format,这一对由于从面向对象哪里得到了赞助,用以写出的代码更觉优雅。

 

 

 

 

sprintf 用法总结(2009-08-25 09:36:24)标签:it   分类:C++
  sprintf,将各种类型的数据够造成字符串。

  sprintf是个变参函数,int sprintf(char *buffer,const char *format[,argument]...);除了前两个参数类型固定外,后面可以接任意多个参数,而它的精华,则在第二个参数:格式化字符串上。

  printf和sprintf都使用格式化字符串来指定串的格式,在格式串内部使 用一些以“%”开头的格式说明符(format specification)来占据一个位置,在后边的变参列表中提供相应的变量,最终函数就会用相应位置的变量来替代那个说明符,产生一个调用者想要的 字符串。

 一、格式化数字字符串

  sprintf最常见的应用之一莫过于把整数打印到字符串中,所以sprintf在大多数场合可以替代itoa.

    %-8d 代表宽度八位,左对齐(没有负号为右对齐),整数的十进制

  %x小写16进制  %X大写16进制

    符号扩展问题:参数压栈默认四字节,即8位16进制。应该让编译器做0扩展而不是符号扩展。

  如  sprintf(s,"%04X",(unsigned short)si);

    %o 8进制格式化字符串。

  控制浮点数打印格式,使用格式符"%f"控制,默认保留小数点后6位数字。

  %m.nf m表示打印的宽度,n表示小数点后的位数

  sprintf(s,"%m.nf",i)其中i 必须为浮点类型的

二、字符/ASCII码对照

  %c打印一个整数,可以看到整数所对应的ASCII值

  for(int i=32 ;i<127;i++)
  {
    printf("[%c]:%3d 0x%#04X/n",i,i,i);
  }

 #与%X合用时自动为16进制数增加“0X”前缀。

三、连接字符串

 可以在许多场合替代strcat,sprintf能够一次连接多个字符串。

 %s可以参照浮点数控制的%m.n m表示宽度,n表示从相应的字符串中最多取用的字符数,通常m没什么用。

  对于动态的,可以采用sprintf(s,"%.*s%.*s",7,a1,7,a2)或sprintf(s,"%.*s%.*s",sizeof(a1),a1,sizeof(a2),a2);  

四、打印地址信息

有时调试程序时,我们可能想查看某些变量或者成员的地址,由于地址或者指针也不过是个32 位的数,你完全可以使用打印无符号整数的”%u”把他们打印出来:
sprintf(s, "%u", &i);
不过通常人们还是喜欢使用16 进制而不是10 进制来显示一个地址:
sprintf(s, "%08X", &i);
然而,这些都是间接的方法,对于地址打印,sprintf 提供了专门的”%p”:
sprintf(s, "%p", &i);
我觉得它实际上就相当于:
sprintf(s, "%0*x", 2 * sizeof(void *), &i);

五、返回值

返回了本次函数调用最终打印到字符缓冲区中的字符数目。
六、strftime

专门用于格式化时间字符串。需调用者指定缓冲区的最大长度。

strftime(s,sizeof(s),"%Y-%m-%d %H:%M:%S",localtime(&t));
posted @ 2013-07-10 15:31 何杨 阅读(272) | 评论 (0)编辑 收藏

http://sddhn.blog.163.com/blog/static/1281877920129191574926/


在DB2中从客户端访问服务器端的数据库时,不能直接用connect命令,而必须先建立通信node,再在node的基础上建立数据库连接。在命令行的具体操作如下:
->db2 catalog tcpip node ${nodeName} remote ${serverName} server ${portNumber} 
->db2 catalog db ${dbName} as ${dbAlias} at node ${nodeName} 
->db2 connect to ${dbAlias} user ${userName} using ${passWord}
->db2 terminate
说明:
${nodeName}:任意起的一个结点名,注意长度限制
${serverName}:远程数据库所在服务器名称或IP地址
${portNumber} :远程数据库端口号
${dbName}:远程数据库的名字
${dbAlias}:编目到本地后的数据库别名
${userName}:连接数据库用户名
${passWord}:连接数据库密码
其他相关一些重要的DB2命令
  1. 查看本地节点目录
  命令窗口中输入:db2 list node directory
  2. 编目一个TCP/IP节点
   命令窗口:db2 catalog tcpip node <node_name> remote <hostname|ip_address> server <svcname|port_number> ostype <OS2|AIX|WIN95|NT|HPUX|SUN|MVS|OS400|VM|VSE|SCO|SGI|LINUX|DYNIX>

Eg: Open a command shell and input the commands below:

db2 catalog tcpip node koubeSvr remote 9.119.100.222 server 50000

db2 catalog db KOUBE23 as KOUBE23 at node koubeSvr

  3. 取消节点编目
  db2 uncatalog node <node_name>
  4. 查看系统数据库目录
  db2 list database directory
  5. 查看本地数据库目录
  db2 list database directory on <盘符>
  在本地数据库目录中有而系统数据库目录中没有的数据库不能访问,可以在控制中心中选中<数据库>右键单击选择添加,然后输入需要添加的数据库名称或者点击刷新按钮选择数据库,加入数据库后即可以访问。
  6. 编目数据库
  db2 catalog database <db_name> as <db_alias> at node <node_name>
  7. 取消数据库编目
  db2 uncatalog database <db_name>
  8. 测试远程数据库的连接
  db2 connect to <db_alias> user <user_id> using <password>
posted @ 2013-07-08 15:23 何杨 阅读(371) | 评论 (0)编辑 收藏

工具:
这个工具用于将ASM文件编译.
http://www.blogjava.net/Files/heyang/nasm-2.07-installer.rar

建议使用Notepad++书写asm,然后用命令行编译:
>nasm a.asm -o a.com

这个工具能将BIN写入软盘扇区:
http://www.blogjava.net/Files/heyang/FloppyWriter.zip

以下是一个例程:
%define _BOOT_DEBUG_
%ifdef _BOOT_DEBUG_
    org 0100h
%else
    org 07c00h
%endif
    mov ax,cs
    mov ds,ax
    mov es,ax
    call DispStr;
    jmp $;
DispStr:
    mov ax,BootMessage
    mov bp,ax
    mov cx,
32
    mov ax,01301h
    mov bx,000ch
    mov dl,
0
    
int 10h
    ret
BootMessage:    db 
"Hello,OS world!XXXXXX is here."
times 
510-($-$$) db 0;
dw 
0xaa55;
posted @ 2013-05-30 20:40 何杨 阅读(178) | 评论 (0)编辑 收藏

/**********************************************
* 获取相对于今天的日期
* 2013年4月29日22:21:23
*********************************************
*/
function GetDateStr(AddDayCount) {
    
var dd = new Date();
    dd.setDate(dd.getDate()
+AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    
    
var m = dd.getMonth()+1;//获取当前月份的日期
    m=parseInt(m,10);
    
if(m<10){
        m
="0"+m;
    }
    
    
var d = dd.getDate();
    d
=parseInt(d,10);
    
if(d<10){
        d
="0"+d;
    }
    
    
return y+"-"+m+"-"+d;
}

示例:
var today=GetDateStr(0);
var yesterday=GetDateStr(-1);
var thedaybeforeyesterday=GetDateStr(-2);

posted @ 2013-05-06 16:56 何杨 阅读(239) | 评论 (0)编辑 收藏

1.dom初始化
$(document).ready(
    function(){
        ...// 这里写初始化
    }
);

2.给所有class为channel的元素设定点击事件.
$('.channel').click(
     function(){
         ...
    }
);

3.给id=menuDiv下的ul下的li中的设定点击事件.
$("#menuDiv>ul>li>a").click{   
    function(){
         ...
    }
);
posted @ 2013-05-02 21:18 何杨 阅读(265) | 评论 (0)编辑 收藏

代码:
<div class="XXX">
    <img class="X" src="XX">
</div>

方法:
设置div与img等高,其height=line-height,这样Img就被DIV夹在中间了.
再设置div的margin-top=margin-bottom,这样上下外边距相等,img就随着div被夹在中间了.
posted @ 2013-04-30 21:10 何杨 阅读(375) | 评论 (0)编辑 收藏

1.调用new Object,如
var obj=new Object();
obj创建出来后没有任何属性或方法,需要手工进行添加
obj.property=XX;
obj.method=function(){...};

2.用大括弧{}来直接描述属性或方法
var obj={property01:value01,property02:value02,...};

3.自定义一个构建函数,然后用new来创建
function func(value01,value02,...,value0n){
     this.property01=value01;
     this.property02=value02;
     ...
     this.property0n=value0n;
}

var obj=new func(v1,v2,..,vn);
posted @ 2013-04-29 16:10 何杨 阅读(264) | 评论 (0)编辑 收藏

仅列出标题
共28页: 上一页 1 2 3 4 5 6 7 8 9 下一页 Last