vs2010 加入 CString a;的时候提示“CString”未声明标识符.

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/shanxuezhe/article/details/80427051

奇怪,难道时我缺少头文件吗,加了#include<Cstring>也不行,还有 #include<afx.h>......


偶然的机会再往上看到了一个回答,

1. 加入 #include <atlstr.h>

2. 将如下的ATl从  “不使用”改为 “动态连接到ATL" ;        //因为我是创建动态库,所以就选择了。



但是之后我又将头文件和 改选项回复到之前的状态,再次编译时,竟然也没有问题,好奇怪 啊???

如哪位大神知道原因,还望不吝赐教!!!





展开阅读全文

vs2010未声明标识符

02-11

// myfirst.cpp--displays a messagernrn#include // a PREPROCESSOR directivernint main() // function headerrn // start of function bodyrn using namespace std; // make definitions visiblern cout << "Come up and C++ me some time."; // messagern cout << endl; // start a new linern cout << "You won't regret it!" << endl; // more outputrn// If the output window closes before you can read it,rn// add the following code:rn // cout << "Press any key to continue." <------ 已启动生成: 项目: ConsoleApplication9, 配置: Debug Win32 ------rn1> ConsoleApplication9.cpprn1>c:\users\time\documents\visual studio 2012\projects\consoleapplication9\consoleapplication9\consoleapplication9.cpp(7): error C2065: “cout”: 未声明的标识符rn1>c:\users\time\documents\visual studio 2012\projects\consoleapplication9\consoleapplication9\consoleapplication9.cpp(8): error C2065: “cout”: 未声明的标识符rn1>c:\users\time\documents\visual studio 2012\projects\consoleapplication9\consoleapplication9\consoleapplication9.cpp(8): error C2065: “endl”: 未声明的标识符rn1>c:\users\time\documents\visual studio 2012\projects\consoleapplication9\consoleapplication9\consoleapplication9.cpp(9): error C2065: “cout”: 未声明的标识符rn1>c:\users\time\documents\visual studio 2012\projects\consoleapplication9\consoleapplication9\consoleapplication9.cpp(9): error C2065: “endl”: 未声明的标识符rn========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========rnrnrnrn大家怎么看? 论坛

vs2010中处理char和CString

07-06

编写个网络聊天的程序,sendto和recvfrom函数中使用char,使用sprintf格式化呢又提示警告,要用format函数,使用CString对象呢经过lParam参数传递后又不好转换,接收端接收到的全是乱码,不知道该如何处理了,代码如下:rn这是接收端的代码rn[code=C/C++]DWORD WINAPI CSX15_CHATDlg::ChatProc(LPVOID lpParam)rnrn SOCKET sock = ((RecvParam*)lpParam)->sock ;rn HWND hWnd = ((RecvParam*)lpParam)->hWnd ;rn SOCKADDR_IN AddrFrom;rn int len = sizeof( SOCKADDR );rnrn char recvBuf[200],recvTemp[400];rnrn while(1)rn rn if( SOCKET_ERROR == recvfrom(sock,recvBuf,200,0,(SOCKADDR*)&AddrFrom,&len))rn rn break;rn rn sprintf(recvTemp,"%s:\n%s",inet_ntoa(AddrFrom.sin_addr ),recvBuf);rn ::PostMessageW(hWnd,WM_RECVDATA,0,(LPARAM)recvTemp); //自定义消息,用OnRecvdata处理rn rn return 0;rn[/code]rn这是发送端的rn[code=C/C++]afx_msg LRESULT CSX15_CHATDlg::OnRecvdata(WPARAM wParam, LPARAM lParam)rnrn CString str,strtemp;rn rn str = (char*)lParam;rn rn GetDlgItemText( IDC_EDIT_RECV,strtemp );rn strtemp += _T("\r\n");rn strtemp += str;rn SetDlgItemText( IDC_EDIT_RECV,strtemp );rn return 0;rnrnrnrnvoid CSX15_CHATDlg::OnBnClickedBtnSend() //发送按钮rnrn // TODO: 在此添加控件通知处理程序代码rn DWORD dwIP;rn ((CIPAddressCtrl*)GetDlgItem(IDC_IPADDRESS1))->GetAddress ( dwIP );rnrn SOCKET socketClient = socket(AF_INET,SOCK_DGRAM,0);rn SOCKADDR_IN addrTo;rn addrTo.sin_addr .S_un .S_addr = htonl(dwIP);rn addrTo.sin_family = AF_INET;rn addrTo.sin_port = htons(6000);rnrn CString sendBuf;rn GetDlgItemText( IDC_EDIT_SEND,sendBuf );rn sendto(m_socket,(const char*)&sendBuf,sendBuf.GetLength () + 1,0,(SOCKADDR*)&addrTo,sizeof( SOCKADDR));rn SetDlgItemText(IDC_EDIT_SEND,_T(""));rn[/code] 论坛

提示error C2065: “i”: 未声明标识符

02-15

/* intHist = computeIntegralHistogramMex(quantMatrix,height,width,prodQuant); computes the integral image of an image with */rnrnrn#include rn#include "mex.h"rnrnvoid mexFunction( int nlhs, mxArray *plhs[],rn int nrhs, const mxArray *prhs[] )rn rnrn int i,j,k,x1;rn double *quantMatrix, *intHist;rn int height,width,prodQuant;rn rn /* Check for proper number of arguments */rn rn if (nrhs != 4) rn mexErrMsgTxt("4 input argument required.");rn rn else if (nlhs > 1) rn mexErrMsgTxt("Too many output arguments.");rn rnrn if ( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) ||rn mxGetNumberOfDimensions(prhs[1]) != 2 )rn mexErrMsgTxt("input 1 (quantMatrix) must be a real double matrix");rn rn quantMatrix = mxGetPr(prhs[0]);rn height = mxGetScalar(prhs[1]);rn width = mxGetScalar(prhs[2]);rn prodQuant = mxGetScalar(prhs[3]);rn rn /* Create a matrix for the return argument */rn rn plhs[0] = mxCreateDoubleMatrix(prodQuant,(height+1)*(width+1),mxREAL);/* size of intHist*/rn rn intHist = mxGetPr(plhs[0]);rnrn rn rn for(i = 1;i <= height;i++)rn for(j = 1;j <= width;j++)rn rn x1 = floor(quantMatrix[(j-1)*height+(i-1)]);rn rn intHist[prodQuant*(j*(height+1)+i)+x1-1]=1; /* corresponding bin has value=1 at location (i,j) */rnrn for(k = 0;k < prodQuant;k++) rn intHist[prodQuant*(j*(height+1)+i)+k] += intHist[prodQuant*(j*(height+1)+i-1)+k] + intHist[prodQuant*((j-1)*(height+1)+i)+k] - intHist[prodQuant*((j-1)*(height+1)+i-1)+k];rn rn rn return; rnrn用Vs2010 提示error C2065: “i”: 未声明的标识符rn还有j,k,x1都是rn不知道是怎么回事呢 论坛

这里的一直提示 未声明标识符 mfc初学者

07-25

程序是mfc编程实现了lr分析器,rn头文件包含如下rn#include "stdafx.h"rn#include "LR.h" rn#include "LRDlg.h"rn#include "afxdialogex.h"rn#include"status_stack.h" //状态栈rn#include"symbol_instr_stack.h" // 符号输入串栈rn#include"llrr.h" 这是lr分析表的一个头文件rnrnBOOL WINAPI Main_Proc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)rnrn switch(uMsg)rn rn //HANDLE_MSG(hWnd,WM_INITDIALOG,Main_OnInitDialog);这里我给注释掉了rn HANDLE_MSG(hWnd,WM_COMMAND,Main_OnCommand);rn HANDLE_MSG(hWnd,WM_CLOSE,Main_OnClose);rn rn return false;rnrnrn之后的Main_OnCommand函数rnvoid Main_OnCommand(HWND hwnd,int id,HWND hwndCtl,UINT codeNotify)rn rn switch(id)rn rn case IDC_BUTTON1:rn rn //初始化各栈rn init_stack(hwnd,status_p);rn init_stack(hwnd,symbol_p);rn init_stack(hwnd,instr_p);rnrn //压进栈初始元素rn push(hwnd,status_p,0);rn push(hwnd,symbol_p,'#');rnrn char x;rn TCHAR msg[256];rn GetDlgItemText(hwnd,IDC_EDIT3,msg,sizeof(msg));rn unsigned int i;rn for(i=0;itop!=0)rn rn x=pop(hwnd,symbol_p);rn push(hwnd,instr_p,x);rn rnrn print(hwnd,status_p,symbol_p,instr_p);rn rn break;rn case IDC_BUTTON2:rn rn action(hwnd,status_p,symbol_p,instr_p);rn rn break;rn case IDC_BUTTON3:rn rn SetDlgItemText(hwnd,IDC_EDIT1,TEXT(""));rn SetDlgItemText(hwnd,IDC_EDIT2,TEXT(""));rn SetDlgItemText(hwnd,IDC_EDIT3,TEXT(""));rn SetDlgItemText(hwnd,IDC_EDIT4,TEXT(""));rn rn break;rn default:rn break;rn rn rnrn之后的Main_OnClose函数rn void Main_OnClose(HWND hwnd)rn rn EndDialog(hwnd,0);rn rnrn程序编译一直提示rn1>c:\users\zj\documents\visual studio 2012\projects\lr\lr\lrdlg.cpp(168): error C2065: “Main_OnCommand”: 未声明的标识符rn1>c:\users\zj\documents\visual studio 2012\projects\lr\lr\lrdlg.cpp(169): error C2065: “Main_OnClose”: 未声明的标识符rnrn网上百度说是头文件顺序问题 可是改了还是提示这样的错误。rn请问谁知道怎么修改这样才可以吗rnmfc初学 求指导 谢谢 论坛

没有更多推荐了,返回首页