C++本地函数定义是非法的
usingnamespacestd;#import"c:\programfiles\commonfiles\system\ado\msado15.dll"no_names...
using namespace std;
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF", "adoEOF")
void main()
{
CoInitialize(NULL);
_ConnectionPtr sqlSp;
HRESULT hr=sqlSp.CreateInstance(_uuidof(Connection));
if(FAILED(hr))
{ cout<<"_ConnectionPtr对象指针实例化失败!!!"<<endl;
return ;
}
else
{
try
{
_bstr_t strConnect="Driver={sql server};server=218.25.140.68,1433;uid=sa;pwd=sa123456;database=JSGL;";
sqlSp->Open(strConnect,"","",adModeUnknown);
_RecordsetPtr m_pRecordset;
if(FAILED(m_pRecordset.CreateInstance( _uuidof( Recordset ))))
{
cout<<"记录集对象指针实例化失败!"<<endl;
return;
}
string FJH,KHSH;
cout<<"请输入分机号"<<endl;
cin>>FJH;
cout<<"请输入客户税号"<<endl;
cin>>KHSH;
string str,str1,str2;
str1="select zcbj,cpzt from XSGL_YDKPZC where fjh=";
str2=" and khsh=";
str=str1+FJH+str2+KHSH;
cout<<str<<endl;
void swap1(string fjh,string khsh)
{
string temp;
temp=fjh;
fjh=khsh;
khsh=temp;
}
int main()
{
string FJH,KHSH;
swap1(FJH,KHSH);
cout<<FJH<<" "<<KHSH<<endl;
}
try
{
string str,str1,str2;
str1="select zcbj,cpzt from XSGL_YDKPZC where fjh=";
str2=" and khsh=";
str=str1+FJH+str2+KHSH;
m_pRecordset->Open("str" ,(IDispatch*)sqlSp,adOpenDynamic,adLockOptimistic, adCmdText);
}
catch (_com_error &e)
{
cout << e.Description()<<endl;
}
try
{
m_pRecordset->MoveFirst();
string cpzt = "";
string zcbj="";
while(!m_pRecordset->adoEOF)
{
cpzt=(char*)(_bstr_t)(m_pRecordset->Fields->GetItem(_variant_t("cpzt"))->Value);
zcbj=(char*)(_bstr_t)(m_pRecordset->Fields->GetItem(_variant_t("zcbj"))->Value);
cout<<cpzt<<endl;
cout<<zcbj<<endl;
m_pRecordset->MoveNext();
}
}
catch (_com_error &e)
{
cout<<"2"<<endl;
}
}
catch(_com_error &e)
{
cout<<"F"<<endl;
}
}
system("pause");
}
第二个int main :main本地定义函数是非法的
swap1 本地定义函数是非法的
swap1 找不到标识符
string temp前面的大括号:IntelliSense: 应输入“;”
头文件
#include "stdafx.h"
#include<icrsint.h>
#include<iostream>
#include<iomanip>
#include<string.h>
#include<string> 展开
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF", "adoEOF")
void main()
{
CoInitialize(NULL);
_ConnectionPtr sqlSp;
HRESULT hr=sqlSp.CreateInstance(_uuidof(Connection));
if(FAILED(hr))
{ cout<<"_ConnectionPtr对象指针实例化失败!!!"<<endl;
return ;
}
else
{
try
{
_bstr_t strConnect="Driver={sql server};server=218.25.140.68,1433;uid=sa;pwd=sa123456;database=JSGL;";
sqlSp->Open(strConnect,"","",adModeUnknown);
_RecordsetPtr m_pRecordset;
if(FAILED(m_pRecordset.CreateInstance( _uuidof( Recordset ))))
{
cout<<"记录集对象指针实例化失败!"<<endl;
return;
}
string FJH,KHSH;
cout<<"请输入分机号"<<endl;
cin>>FJH;
cout<<"请输入客户税号"<<endl;
cin>>KHSH;
string str,str1,str2;
str1="select zcbj,cpzt from XSGL_YDKPZC where fjh=";
str2=" and khsh=";
str=str1+FJH+str2+KHSH;
cout<<str<<endl;
void swap1(string fjh,string khsh)
{
string temp;
temp=fjh;
fjh=khsh;
khsh=temp;
}
int main()
{
string FJH,KHSH;
swap1(FJH,KHSH);
cout<<FJH<<" "<<KHSH<<endl;
}
try
{
string str,str1,str2;
str1="select zcbj,cpzt from XSGL_YDKPZC where fjh=";
str2=" and khsh=";
str=str1+FJH+str2+KHSH;
m_pRecordset->Open("str" ,(IDispatch*)sqlSp,adOpenDynamic,adLockOptimistic, adCmdText);
}
catch (_com_error &e)
{
cout << e.Description()<<endl;
}
try
{
m_pRecordset->MoveFirst();
string cpzt = "";
string zcbj="";
while(!m_pRecordset->adoEOF)
{
cpzt=(char*)(_bstr_t)(m_pRecordset->Fields->GetItem(_variant_t("cpzt"))->Value);
zcbj=(char*)(_bstr_t)(m_pRecordset->Fields->GetItem(_variant_t("zcbj"))->Value);
cout<<cpzt<<endl;
cout<<zcbj<<endl;
m_pRecordset->MoveNext();
}
}
catch (_com_error &e)
{
cout<<"2"<<endl;
}
}
catch(_com_error &e)
{
cout<<"F"<<endl;
}
}
system("pause");
}
第二个int main :main本地定义函数是非法的
swap1 本地定义函数是非法的
swap1 找不到标识符
string temp前面的大括号:IntelliSense: 应输入“;”
头文件
#include "stdafx.h"
#include<icrsint.h>
#include<iostream>
#include<iomanip>
#include<string.h>
#include<string> 展开
1个回答
展开全部
void swap1(string fjh,string khsh)
{
string temp;
temp=fjh;
fjh=khsh;
khsh=temp;
}
int main()
{
string FJH,KHSH;
swap1(FJH,KHSH);
cout<<FJH<<" "<<KHSH<<endl;
}
这里,这些个是在main函数里面的,怎么能在函数里面套用函数定义呢?而且,函数只能有一个main函数,这里怎么能有两个main函数呢?
{
string temp;
temp=fjh;
fjh=khsh;
khsh=temp;
}
int main()
{
string FJH,KHSH;
swap1(FJH,KHSH);
cout<<FJH<<" "<<KHSH<<endl;
}
这里,这些个是在main函数里面的,怎么能在函数里面套用函数定义呢?而且,函数只能有一个main函数,这里怎么能有两个main函数呢?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询