欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

15種?C++?常見報錯原因分析

 更新時間:2023年01月03日 14:25:20   作者:zeekliu  
這篇文章主要介紹了15種?C++?常見報錯,本文通過實例代碼給大家講解的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

本文整合了部分 C/C++ 常見的報錯原因,可根據(jù)自己的情況,使用目錄跳轉(zhuǎn)。

1 重定義變量

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a;
	cin>>a;
	int a;
	cout<<a<<endl;
}

Error:redefinition of 'a'

改為:

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a;
	cin>>a;
	cout<<a<<endl;
}

2  缺少分號

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a;
	cout<<a<<endl
}

Error:expected ';' after expression

改為:

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a;
	cout<<a<<endl;
}

3 數(shù)組維數(shù)錯誤

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a[101][101];
	a[0]=1;
	cout<<a[0]<<endl;;
}

Error:array type 'int [101]' is not assignable

改為:

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a[101];
	a[0]=1;
	cout<<a[0]<<endl;;
}

4  關(guān)于 if 與 else

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a;
	cin>>a;
	if (a==1;) a=2;
}

Error:expected expression

Warning: equality comparison result unused [-Wunused-comparison]

if 判斷里不能有分號!

改為:

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a;
	cin>>a;
	if (a==1) a=2;
}

5  關(guān)于 if 與 else

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a;
	cin>>a;
	if (a=1) a=2;
}

這個是把等號寫成了賦值號

 Warning: using the result of an assignment as a condition without parentheses [-Wparentheses]

這個超級坑爹,因為不少編譯器遇到這種問題有的還不報錯,只是有Warning,而且看半天才能看出來

應(yīng)改為:

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a;
	cin>>a;
	if (a==1) a=2;
}

6  括號匹配錯誤

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a[10];
	a[1=(a[1+1)*1);
	}
 
}

Error: expected ']'

Error: expected ']'

Error: extraneous closing brace ('}')

應(yīng)改為:

#include <bits/stdc++.h>
using namespace std;
char c[101];
 
int main() 
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>c+1;
	return 0;
}

===========Upd: 22-05-19============

7  關(guān)于字符串的輸入錯誤 (*)

#include <bits/stdc++.h>
using namespace std;
char c[101];
 
int main() 
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>c+1;
	return 0;
}

(MacOS??????)

Error:  invalid operands to binary expression ('std::istream' (aka 'basic_istream<char>') and 'char *')
        cin>>c+1;
        ~~~^ ~~~

Warning: operator '>>' has lower precedence than '+'; '+' will be evaluated first [-Wshift-op-parentheses]
        cin>>c+1;
           ~~~^~

和一堆 note:

Note: candidate function template not viable: no known conversion from 'std::istream' (aka 'basic_istream<char>') to 'std::byte' for 1st argument
  operator>> (byte  __lhs, _Integer __shift) noexcept
  ^

(這句話至少出現(xiàn)了50次)

那么為什么打*呢?

因為 Linux 系統(tǒng)編譯通過!

Windows 尚未測試,有興趣的小伙伴可以自測一下然后私信,歡迎私信~~~。

(這個問題源于我自己做題時,我看標(biāo)準(zhǔn)代碼,不知為什么就是編譯不對,結(jié)果提交以后就AC了??。?/p>

8  寫錯函數(shù) / 變量名

這個情況下,有時候編譯器可能會猜測你要寫的名字,比如:

#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a=1,b=2;
	mam(a,b);
	return 0;
}

Error: use of undeclared identifier 'mam'; did you mean 'max'?

如果編譯器沒有類似提示,就仔細(xì)想想應(yīng)該是什么吧。

到此這篇關(guān)于15種 C++ 常見報錯的文章就介紹到這了,更多相關(guān)C++ 常見報錯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • QT中進(jìn)程的創(chuàng)建實現(xiàn)

    QT中進(jìn)程的創(chuàng)建實現(xiàn)

    本文主要介紹了QT中進(jìn)程的創(chuàng)建實現(xiàn),詳細(xì)介紹了創(chuàng)建進(jìn)程的整個過程,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2023-08-08
  • Clion2020.2.x最新激活碼破解版附安裝教程(Mac Linux Windows)

    Clion2020.2.x最新激活碼破解版附安裝教程(Mac Linux Windows)

    Clion2020增加了很多新特性,修復(fù)了大量bug,大大提高了開發(fā)效率。這篇文章主要介紹了Clion2020.2.x最新激活碼破解版附安裝教程(Mac Linux Windows),需要的朋友可以參考下
    2020-11-11
  • OpenCV透視變換應(yīng)用之書本視圖矯正+廣告屏幕切換

    OpenCV透視變換應(yīng)用之書本視圖矯正+廣告屏幕切換

    透視變換是指利用透視中心、像點、目標(biāo)點三點共線的條件,按透視旋轉(zhuǎn)定律使承影面繞跡線旋轉(zhuǎn)某一角度,破壞原有的投影光線束,仍能保持承影面上投影幾何圖形不變的變換。本文將為大家介紹兩個OpenCV透視變換應(yīng)用,需要的可以參考一下
    2022-08-08
  • C語言對對碰游戲源碼分享

    C語言對對碰游戲源碼分享

    這篇文章主要為大家分享了C語言對對碰游戲源碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • C++輕量級界面開發(fā)框架ImGUI介紹小結(jié)

    C++輕量級界面開發(fā)框架ImGUI介紹小結(jié)

    如果從事過C++?Windows客戶端開發(fā),大家對MFC、Qt、DuiLib等各種DirectUI應(yīng)該有了解,本篇給大家介紹一個超級輕量級的C++開源跨平臺圖形界面框架ImGUI,感興趣的可以了解一下
    2021-11-11
  • C語言設(shè)計三子棋小游戲

    C語言設(shè)計三子棋小游戲

    這篇文章主要為大家詳細(xì)介紹了C語言設(shè)計三子棋小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-04-04
  • C語言示例講解if else語句的用法

    C語言示例講解if else語句的用法

    這篇文章主要介紹C語言中的If Else語句怎么使用,在日常操作中,相信很多人在If Else語句怎么使用問題上存在疑惑,小編查閱了各式資料,整理出使用方法,接下來,請跟著小編一起來學(xué)習(xí)吧
    2022-06-06
  • C語言 鏈?zhǔn)蕉鏄浣Y(jié)構(gòu)詳解原理

    C語言 鏈?zhǔn)蕉鏄浣Y(jié)構(gòu)詳解原理

    二叉樹的鏈?zhǔn)酱鎯Y(jié)構(gòu)是指,用鏈表來表示一棵二叉樹,即用鏈來指示元素的邏輯關(guān)系。通常的方法是鏈表中每個結(jié)點由三個域組成,數(shù)據(jù)域和左右指針域,左右指針分別用來給出該結(jié)點左孩子和右孩子所在的鏈結(jié)點的存儲地址
    2021-11-11
  • C++實現(xiàn)LeetCode(38.計數(shù)和讀法)

    C++實現(xiàn)LeetCode(38.計數(shù)和讀法)

    這篇文章主要介紹了C++實現(xiàn)LeetCode(38.計數(shù)和讀法),本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • c++ 排查內(nèi)存泄漏的妙招

    c++ 排查內(nèi)存泄漏的妙招

    這篇文章主要介紹了c++ 如何用輔助類排查內(nèi)存泄漏,幫助大家更好的理解和學(xué)習(xí)使用c++,感興趣的朋友可以了解下
    2021-03-03

最新評論