C++ 錯誤提示:無法將引數1從const char [8] 轉換為char *
#include <iostream>
using namespace std;
void test(char * p)
{
cout << p << endl;
}
int main(void)
{
test("geerniya");
system("pause");
}
在將字串當做函式引數傳遞給函式時,如上所示。編譯器會報錯C2664 “void test(char *)”: 無法將引數 1 從“const char [12]”轉換為“char *”
。當把test()函式中的形參改為const char * p
原因應該是函式的實參與形參型別不匹配, 字串在記憶體中是一個常量字串陣列,因此在函式中的形參也應當加上const關鍵字才行。
改好後的程式如下:
#include <iostream>
using namespace std;
void test(const char * p)
{
cout << p << endl;
}
int main(void)
{
test("geerniya");
system("pause");
}
相關推薦
C++ 錯誤提示:無法將引數1從const char [8] 轉換為char *
#include <iostream> using namespace std; void test(char * p) { cout << p << endl; } int main(void) { test("geerniya")
無法將引數1從“const char [6]”轉換為“char *”的解決方法
有一些C++程式在VS2017上執行會有一些錯誤,而在vc6.0中卻能執行出來。接下來的一個程式就是我在vs2017上執行出現錯誤,而在vc6.0上執行出來。但我已經通過分析vs2017上錯誤來源解決了該問題,並以此作為分享。例項碼:#include<i
VC2008編譯出現error2664錯誤:Format(const wchar_t *,...)”:不能將引數 1 從“const char [4]”轉換為“const wchar_t *”
void scesjk::OnBnClickedButton1() //資料記錄 { // TODO: 在此新增控制元件通知處理程式程式碼 UpdateData(true); m_set.Open(); m_set.A
[error2664:Format(const wchar_t *,...)”:不能將引數 1 從“const char [4]”轉換為“const wchar_t *”]的解決
void scesjk::OnBnClickedButton1() //資料記錄 { // TODO: 在此新增控制元件通知處理程式程式碼 UpdateData(true); m_set.Open(); m_set.A
:MessageBoxW”: 不能將引數 1 從“const char [5]”轉換為“LPCTSTR” 1> 與指向的型別無關;轉換要求 reinterpret_cast、C 樣式
MessageBox("系統選單","提示",MB_OK|MB_ICONINFORMATION); MessageBox(_T("系統選單"),_T("提示"),MB_OK|MB_ICONINFORMATION); 或MessageBox(L"系統選單",L"提示"
MFC遇到的一個字符集問題:不能將引數1從“const char []”轉換為“LPCTSTR”
1、ANSI(即MBCS):為多位元組字符集,它是不定長表示世界文字的編碼方式。ANSI表示英文字母時就和ASCII一樣,但表示其他文字時就需要用多位元組。2、Unicode:用兩個位元組表示一個字元的編碼方式。比如字元'A'在ASCII下面用一個位元組表示,而在Unicode下面用兩個位元組表示,其中高位元
Unity3d(C#)錯誤提示:禁止線上程中進行遊戲物件比較!
今天剛剛寫完非同步Socket客戶端的資料收發,在進行測試的時候,Unity報出錯誤: CompareBaseObjectsInternal can only be called from the main thread. 詳情如下: ERROR : CompareB
WIN7下編譯NIOS2出現如下錯誤提示:make:***[**.mk] Error 1 或者 make: *** [**.elf] Error 1
我的系統是WIN7,QuartusII和NIOS2的版本都是10.0,按照特權同學的《特權和你一起學NIOS2--第三章 流程實踐案例——手把手第一個工程》操作,前面都很順利,後來在Eclipse裡建好了軟體工程之後,編譯(Build Project),出現如下錯誤提示:m
解決 C2664 “char *strcpy(char *,const char *)”: 無法將引數 2 從“CString”轉換為“const char *”
在使用舊工程中的函式時, 在VS 2017上編譯出現如上問題, 但是該函式在之前的版本上可以正常編譯, 怎麼會出現這問題呢?難道不向前相容, 不應該, 一定是哪裡沒設定好, 在找資料查詢之後, 還是找到了, 記錄下, 方便大家也方便自己. 1. 編譯錯誤顯示圖
【VC++】不能將引數 1 從“_TCHAR”轉換為“const char* 問題解決
原因:2005預設的"使用 Unicode 字符集",解決:在你建立的解決方案的工程檔案的屬性看到選"配置屬性"的"字符集"請選擇"使用多位元組字符集"就可以了。 2005開啟6.0的檔案時候不會出現的這樣的錯誤,是因為編譯環境在轉換過程中進行了轉換. 這個解決辦法在vs 2008也適用。
C++編譯出現 error C2664: 不能將引數 2 從“const char [5]”轉換為“LPCTSTR”解決辦法。
原因:編譯程式的時候出現這樣的錯誤,原因是在新建MFC專案的時候,設定字符集Unicode的屬性 解決方法一: 在VS的解決方案管理器視窗內,右擊你的專案“專案”,然後選“屬性”(最後一項),再點“配
inet_addr”: 不能將引數 1 從“CString”轉換為“const char *”1>
CString ipaddress; ipaddress = "192.168.39.207"; DWORD m_dwPuIp; m_dwPuIp = inet_addr(ipaddress);有一個錯誤:“inet_addr”: 不能將引數 1 從“CString”轉換為
不能將引數 2 從“const char [7]”轉換為“LPCTSTR”問題解決辦法
如下語句: ctrlList.InsertColumn(0, "屬性頁", LVCFMT_LEFT, 300, 0); 使用VS2005編譯時提示如下錯誤資訊: error C2664: “int CListCtrl::InsertColumn(int,LPCTSTR,in
error C2662: 無法將this指標從const轉化為非const
今天在寫程式時遇到了一個報錯: error C2662: 'x' : cannot convert 'this' pointer from 'const class Point3d' to 'class Point3d &' 先看下程式碼: #include &l
.Net EF 無法將型別"System.Data.EntityState"隱式轉換為"System.Data.Entity.EntityState"
出現這個錯誤通常是因為新增模型時自動安裝的EntityFramework 版本不一致, 這個時候可以直接引用專案裡面的dll檔案 如 專案資料夾\packages\EntityFramework.5.0.0\lib\net45\EntityFramework.dll 實在找
bartender鏈接數據庫提示:無法鏈接到數據庫 外部數據驅動程序(1)中的意外錯誤#6670
bartender 6670 外部數據驅動程序bartender鏈接數據庫提示:無法鏈接到數據庫 外部數據驅動程序(1)中的意外錯誤#6670是 微軟 10月份更新的補丁導致。解決:1.關閉自動更新2.卸載補丁:win7 KB4041678 KB404168
Mac 解壓zip檔案錯誤:無法將"*.zip"解壓縮到"" (錯誤 1-操作不被允許)
錯誤提示: 無法將"*.zip"解壓縮到"" (錯誤 1-操作不被允許)或者 解壓縮失敗 英文提示: "Unable to unarchive into file path" (Error 1 - Operation not permitted.) o
錯誤提示:未處理的“System.NullReferenceException”類型的異常出現在 system.data.dll 中。 其他信息: 未將對象引用設置到對象的實例。
錯誤 reference tar RM 問題 一個 ext ID dll 這種情況的發生一般有3種情況:1.代碼中有一個對象沒有初始化。例如Form A=new Form();2.連接數據庫的問題。連接和打開連接的語句。3.T-SQL語句不正確,引起在訪問數據庫時有問題。錯
啟動MongoDB提示:無法啟動此程式,因為計算機中丟失api-ms-win-crt-runtime-|1-1-0.dll
前提:已完成好MongoDB 進入MongoDB安裝根目錄下的bin目錄下,啟動MongoDB 啟動mongod.exe提示“無法啟動此程式,因為計算機中丟失api-ms-win-crt-runtime-|1-1-0.dll” 解決方法 微軟官方提供的 vc_
oracle 刪除表空間錯誤 提示:ora-02429:無法刪除用於強制唯一/主鍵的索引
sql>drop tablespace ksdm ora-01549:表空間非空,請使用INCLUDING CONTENTS 選項 sql>drop tablespace ksdm INCLUDING CONTENTS and datafiles; ora-00604:遞迴sql層1出現錯誤。