c++

获取时间,没有CString 的format 其实也有更优雅的。

下面的代码直接拷贝去运行就可以了

#include<iostream>
#include<time.h>
using namespace std;
void main()
{
 struct tm *pTm;
 time_t t;
 t=time(NULL);
 pTm=localtime(&t);
 //cout<<pTm->tm_hour<<endl; //这样就可以获得小时,注意使用strftime
 char szStr[64];
 memset(szStr,0,sizeof(szStr));
 //数据库的时间格式 2009-08-19 15:42:51
 strftime(szStr,100,"%Y-%m-%d %H:%M:%S",pTm);
 cout<<szStr<<endl;
 getchar();
}

2.前些日子用otl,里面有重载了<<,想输出__int64不行。怎么办。

最终是先用 double获得具体指(有15位),再强制转换成(__int64),再用 std::cout来进行数据。终于解决了。另外C++的long是32位,java的long是64位。。。。所以用java的话其实就不用经过转换了。很舒服

贴程序:

void main(void)   //如果打印出来的是100就是正常的
{  

 __int64 i;
 double b;
 b=100.01110;
 //printf("%lld",i);
 i=(_int64)b;
 cout<<i;
 getchar();
  Sleep(11000);
}

3. 一个最基本的FTP,用来验证账号是否有效

// string m_strServer,m_strUserName,m_strPassword;
// m_strServer="";
// m_strUserName="";
// m_strPassword="";
// CString str;
// CInternetSession* m_pInetSession=new CInternetSession(_T("aaa"),1,PRE_CONFIG_INTERNET_ACCESS);
// CFtpConnection* m_pFtpConnection;
// try
// {
// m_pFtpConnection=m_pInetSession->GetFtpConnection(_T("127.2.3"),_T("admin"),_T("admin"));
// }
// catch(CInternetException *e)
// {
// TCHAR szError[1024];
// if(e->GetErrorMessage(szError,1024))
// {
// cout<<szError<<endl;
//
// }
// else
// {
// cout<<"There was an exception"<<endl;
// }
// //delete m_pInetSession;
// m_pFtpConnection=NULL;
//  
// }

原文地址:https://www.cnblogs.com/xianqingzh/p/1558661.html