初学cpp<class类01>

本文通过一个C++类的应用实例,介绍了如何使用类来管理日期相关的数据和操作,包括日期的显示、设置以及判断是否为周末等实用功能。
//运用class例题

#include<iostream>
using namespace std;
class Date
{
private:
	int Year;
	int Month;
	int Day;
public:
	Date(){}//默认构造函数
	Date(int y,int m,int d);//构造函数
	void ShowDate();
	void SetYear(int y);
	void SetMonth(int m);
	void SetDay(int d);
	Date NextDay();//定义Date型的函数,将Date型的值返回
	bool IsWeekend();
	//~Date(){cout<<"执行析构函数\n";};//析构函数
};

Date::Date(int y,int m,int d)
{
	Year=y;
	Month=m;
	Day=d;
}

void Date::ShowDate()//显示日期
{
	cout<<Year<<"-"<<Month<<"-"<<Day<<endl;
}

void Date::SetYear(int y)//设置年份
{
	Year=y;
}

void Date::SetMonth(int m)//设置月份
{
	Month=m;
}

void Date::SetDay(int d)//设置日期
{
	Day=d;
}

Date Date::NextDay()           //设置后的第二天的日期
{
	bool IsLeapyear(int);
	Date today;              //定义一个将要返回的Date类的值
	today.Year=Year;       //将刚定义的today 初始化
	today.Month=Month;
	today.Day=Day;
	int mon[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
	if(IsLeapyear(today.Year)==true)
	{
		today.Day++;
		if(today.Day>mon[Month])
		{
			today.Day=1;
			today.Month++;
			if(today.Month>12)
			{
				today.Month=1;
				today.Year++;
			}
		}
	}
	else
	{
		mon[2]=28;
		today.Day++;
		if(today.Day>mon[Month])
		{
			today.Day=1;
			today.Month++;
			if(today.Month>12)
			{
				today.Month=1;
				today.Year++;
			}
		}
	}
	//cout<<Year<<"-"<<Month<<"-"<<Day<<endl;
	return today;
}

bool Date::IsWeekend()     //判断是否为周末
{
	bool IsLeapyear(int);
	int days,i;
	int mon[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
	days=0;
	for(i=1;i<Year;i++)
		if(IsLeapyear(i)==true)
			days+=366;
		else
			days+=365;
	if(Month<2)
		days=days+31+Day;
	else
	{
		if(IsLeapyear(Year)==true)
		{
			for(i=1;i<Month;i++)
				days+=mon[i];
			days+=Day;
		}
		else
		{
			for(i=1;i<Month;i++)
				days+=mon[i];
			days+=Day;
			days--;
		}
	}
	if(days%7==0||days%7==6)
		return true;
	else
		return false;
}

bool IsLeapyear(int Year)     //判断是否为闰年
{
	if(Year%4==0&&Year%100!=0||Year%400==0)
		return true;
	else
		return false;
}

int main()
{
	int y,m,d;
	Date tomorrow;
	//t.ShowDate();
	Date today(2012,2,11);
	today.ShowDate();
	cout<<"please input year:";
	cin>>y;
	cout<<"after set time :\n";
	today.SetYear(y);
	today.ShowDate();
	cout<<"please input month:";
	cin>>m;
	cout<<"after set time :\n";
	today.SetMonth(m);
	today.ShowDate();
	cout<<"please input day:";
	cin>>d;
	today.SetDay(d);
	cout<<"after set time :\n";
	today.ShowDate();
	if(today.IsWeekend()==true)
		cout<<"today is weekend !\n\n";
	else
		cout<<"today is not weekend .\n\n";
	//cout<<"Today is Arbor Day !\n";
	cout<<"Tomorrow's Date is:\n";
	tomorrow=today.NextDay();   //执行函数,将today的下一天给tomorrow
	tomorrow.ShowDate();
	if(tomorrow.IsWeekend()==true)
		cout<<"tomorrow is weekend !\n\n";
	else
		cout<<"tomorrow is not weekend .\n\n";
	system("PAUSE");
	return 0;
}

a.cpp: In function ‘int main()’: a.cpp:7:16: error: no match for ‘operator>>’ (operand types are ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} and ‘<unresolved overloaded function type>’) 7 | cin>>number>>endl; | ~~~~~~~~~~~^~~~~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:120:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__istream_type& (*)(std::basic_istream<_CharT, _Traits>::__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 120 | operator>>(__istream_type& (*__pf)(__istream_type&)) | ^~~~~~~~ /usr/include/c++/11/istream:120:36: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)’ {aka ‘std::basic_istream<char>& (*)(std::basic_istream<char>&)’} 120 | operator>>(__istream_type& (*__pf)(__istream_type&)) | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/istream:124:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__ios_type& (*)(std::basic_istream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>; std::basic_istream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]’ 124 | operator>>(__ios_type& (*__pf)(__ios_type&)) | ^~~~~~~~ /usr/include/c++/11/istream:124:32: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::basic_istream<char>::__ios_type& (*)(std::basic_istream<char>::__ios_type&)’ {aka ‘std::basic_ios<char>& (*)(std::basic_ios<char>&)’} 124 | operator>>(__ios_type& (*__pf)(__ios_type&)) | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ /usr/include/c++/11/istream:131:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 131 | operator>>(ios_base& (*__pf)(ios_base&)) | ^~~~~~~~ /usr/include/c++/11/istream:131:30: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::ios_base& (*)(std::ios_base&)’ 131 | operator>>(ios_base& (*__pf)(ios_base&)) | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~ /usr/include/c++/11/istream:168:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 168 | operator>>(bool& __n) | ^~~~~~~~ /usr/include/c++/11/istream:168:24: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘bool&’ 168 | operator>>(bool& __n) | ~~~~~~^~~ /usr/include/c++/11/istream:172:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]’ 172 | operator>>(short& __n); | ^~~~~~~~ /usr/include/c++/11/istream:172:25: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘short int&’ 172 | operator>>(short& __n); | ~~~~~~~^~~ /usr/include/c++/11/istream:175:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 175 | operator>>(unsigned short& __n) | ^~~~~~~~ /usr/include/c++/11/istream:175:34: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘short unsigned int&’ 175 | operator>>(unsigned short& __n) | ~~~~~~~~~~~~~~~~^~~ /usr/include/c++/11/istream:179:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]’ 179 | operator>>(int& __n); | ^~~~~~~~ /usr/include/c++/11/istream:179:23: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘int&’ 179 | operator>>(int& __n); | ~~~~~^~~ /usr/include/c++/11/istream:182:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 182 | operator>>(unsigned int& __n) | ^~~~~~~~ /usr/include/c++/11/istream:182:32: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘unsigned int&’ 182 | operator>>(unsigned int& __n) | ~~~~~~~~~~~~~~^~~ /usr/include/c++/11/istream:186:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 186 | operator>>(long& __n) | ^~~~~~~~ /usr/include/c++/11/istream:186:24: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long int&’ 186 | operator>>(long& __n) | ~~~~~~^~~ /usr/include/c++/11/istream:190:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 190 | operator>>(unsigned long& __n) | ^~~~~~~~ /usr/include/c++/11/istream:190:33: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long unsigned int&’ 190 | operator>>(unsigned long& __n) | ~~~~~~~~~~~~~~~^~~ /usr/include/c++/11/istream:195:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 195 | operator>>(long long& __n) | ^~~~~~~~ /usr/include/c++/11/istream:195:29: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long long int&’ 195 | operator>>(long long& __n) | ~~~~~~~~~~~^~~ /usr/include/c++/11/istream:199:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 199 | operator>>(unsigned long long& __n) | ^~~~~~~~ /usr/include/c++/11/istream:199:38: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long long unsigned int&’ 199 | operator>>(unsigned long long& __n) | ~~~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/11/istream:214:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 214 | operator>>(float& __f) | ^~~~~~~~ /usr/include/c++/11/istream:214:25: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘float&’ 214 | operator>>(float& __f) | ~~~~~~~^~~ /usr/include/c++/11/istream:218:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 218 | operator>>(double& __f) | ^~~~~~~~ /usr/include/c++/11/istream:218:26: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘double&’ 218 | operator>>(double& __f) | ~~~~~~~~^~~ /usr/include/c++/11/istream:222:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 222 | operator>>(long double& __f) | ^~~~~~~~ /usr/include/c++/11/istream:222:31: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘long double&’ 222 | operator>>(long double& __f) | ~~~~~~~~~~~~~^~~ /usr/include/c++/11/istream:235:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ 235 | operator>>(void*& __p) | ^~~~~~~~ /usr/include/c++/11/istream:235:25: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘void*&’ 235 | operator>>(void*& __p) | ~~~~~~~^~~ /usr/include/c++/11/istream:259:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]’ 259 | operator>>(__streambuf_type* __sb); | ^~~~~~~~ /usr/include/c++/11/istream:259:36: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::basic_istream<char>::__streambuf_type*’ {aka ‘std::basic_streambuf<char>*’} 259 | operator>>(__streambuf_type* __sb); | ~~~~~~~~~~~~~~~~~~^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:45, from a.cpp:1: /usr/include/c++/11/cstddef:132:5: note: candidate: ‘template<class _IntegerType> constexpr std::__byte_op_t<_IntegerType> std::operator>>(std::byte, _IntegerType)’ 132 | operator>>(byte __b, _IntegerType __shift) noexcept | ^~~~~~~~ /usr/include/c++/11/cstddef:132:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_IntegerType’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/string:56, from /usr/include/c++/11/bits/locale_classes.h:40, from /usr/include/c++/11/bits/ios_base.h:41, from /usr/include/c++/11/ios:42, from /usr/include/c++/11/istream:38, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/bits/basic_string.tcc:1485:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)’ 1485 | operator>>(basic_istream<_CharT, _Traits>& __in, | ^~~~~~~~ /usr/include/c++/11/bits/basic_string.tcc:1485:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Alloc’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/istream:1016, from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/bits/istream.tcc:958:5: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT&) [with _CharT = char; _Traits = std::char_traits<char>]’ 958 | operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c) | ^~~~~~~~ /usr/include/c++/11/bits/istream.tcc:958:62: note: no known conversion for argument 2 from ‘<unresolved overloaded function type>’ to ‘char&’ 958 | operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c) | ~~~~~~~~^~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:756:5: note: candidate: ‘template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char&)’ 756 | operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c) | ^~~~~~~~ /usr/include/c++/11/istream:756:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘unsigned char&’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:761:5: note: candidate: ‘template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char&)’ 761 | operator>>(basic_istream<char, _Traits>& __in, signed char& __c) | ^~~~~~~~ /usr/include/c++/11/istream:761:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘signed char&’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:859:5: note: candidate: ‘template<class _CharT, class _Traits, long unsigned int _Num> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT (&)[_Num])’ 859 | operator>>(basic_istream<_CharT, _Traits>& __in, _CharT (&__s)[_Num]) | ^~~~~~~~ /usr/include/c++/11/istream:859:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Num’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:868:5: note: candidate: ‘template<class _Traits, long unsigned int _Num> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char (&)[_Num])’ 868 | operator>>(basic_istream<char, _Traits>& __in, unsigned char (&__s)[_Num]) | ^~~~~~~~ /usr/include/c++/11/istream:868:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Num’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:873:5: note: candidate: ‘template<class _Traits, long unsigned int _Num> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char (&)[_Num])’ 873 | operator>>(basic_istream<char, _Traits>& __in, signed char (&__s)[_Num]) | ^~~~~~~~ /usr/include/c++/11/istream:873:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Num’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/sstream:38, from /usr/include/c++/11/complex:45, from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/istream:1006:5: note: candidate: ‘template<class _Istream, class _Tp> _Istream&& std::operator>>(_Istream&&, _Tp&&)’ 1006 | operator>>(_Istream&& __is, _Tp&& __x) | ^~~~~~~~ /usr/include/c++/11/istream:1006:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Tp’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54, from a.cpp:1: /usr/include/c++/11/complex:501:5: note: candidate: ‘template<class _Tp, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::complex<_Tp>&)’ 501 | operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x) | ^~~~~~~~ /usr/include/c++/11/complex:501:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Tp’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:66, from a.cpp:1: /usr/include/c++/11/bitset:1472:5: note: candidate: ‘template<class _CharT, class _Traits, long unsigned int _Nb> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::bitset<_Nb>&)’ 1472 | operator>>(std::basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x) | ^~~~~~~~ /usr/include/c++/11/bitset:1472:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Nb’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:71:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Resetiosflags)’ 71 | operator>>(basic_istream<_CharT, _Traits>& __is, _Resetiosflags __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:71:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘std::_Resetiosflags’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:101:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setiosflags)’ 101 | operator>>(basic_istream<_CharT, _Traits>& __is, _Setiosflags __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:101:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘std::_Setiosflags’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:132:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setbase)’ 132 | operator>>(basic_istream<_CharT, _Traits>& __is, _Setbase __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:132:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘std::_Setbase’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:170:5: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setfill<_CharT>) [with _CharT = char; _Traits = std::char_traits<char>]’ 170 | operator>>(basic_istream<_CharT, _Traits>& __is, _Setfill<_CharT> __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:170:71: note: no known conversion for argument 2 from ‘<unresolved overloaded function type>’ to ‘std::_Setfill<char>’ 170 | operator>>(basic_istream<_CharT, _Traits>& __is, _Setfill<_CharT> __f) | ~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/11/iomanip:200:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setprecision)’ 200 | operator>>(basic_istream<_CharT, _Traits>& __is, _Setprecision __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:200:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘std::_Setprecision’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:230:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setw)’ 230 | operator>>(basic_istream<_CharT, _Traits>& __is, _Setw __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:230:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘std::_Setw’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:264:5: note: candidate: ‘template<class _CharT, class _Traits, class _MoneyT> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Get_money<_MoneyT>)’ 264 | operator>>(basic_istream<_CharT, _Traits>& __is, _Get_money<_MoneyT> __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:264:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_MoneyT’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:72, from a.cpp:1: /usr/include/c++/11/iomanip:418:5: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Get_time<_CharT>) [with _CharT = char; _Traits = std::char_traits<char>]’ 418 | operator>>(basic_istream<_CharT, _Traits>& __is, _Get_time<_CharT> __f) | ^~~~~~~~ /usr/include/c++/11/iomanip:418:72: note: no known conversion for argument 2 from ‘<unresolved overloaded function type>’ to ‘std::_Get_time<char>’ 418 | operator>>(basic_istream<_CharT, _Traits>& __is, _Get_time<_CharT> __f) | ~~~~~~~~~~~~~~~~~~^~~ In file included from /usr/include/c++/11/valarray:603, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/bits/valarray_after.h:414:5: note: candidate: ‘template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__shift_right, typename _Dom1::value_type>::result_type> std::operator>>(const std::_Expr<_Dom1, typename _Dom1::value_type>&, const std::_Expr<_Dom2, typename _Dom2::value_type>&)’ 414 | _DEFINE_EXPR_BINARY_OPERATOR(>>, struct std::__shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/bits/valarray_after.h:414:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} is not derived from ‘const std::_Expr<_Dom1, typename _Dom1::value_type>’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/valarray:603, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/bits/valarray_after.h:414:5: note: candidate: ‘template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__shift_right, typename _Dom1::value_type>::result_type> std::operator>>(const std::_Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)’ 414 | _DEFINE_EXPR_BINARY_OPERATOR(>>, struct std::__shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/bits/valarray_after.h:414:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} is not derived from ‘const std::_Expr<_Dom1, typename _Dom1::value_type>’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/valarray:603, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/bits/valarray_after.h:414:5: note: candidate: ‘template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__shift_right, typename _Dom1::value_type>::result_type> std::operator>>(const typename _Dom::value_type&, const std::_Expr<_Dom1, typename _Dom1::value_type>&)’ 414 | _DEFINE_EXPR_BINARY_OPERATOR(>>, struct std::__shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/bits/valarray_after.h:414:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Dom’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/valarray:603, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/bits/valarray_after.h:414:5: note: candidate: ‘template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__shift_right, typename _Dom1::value_type>::result_type> std::operator>>(const std::_Expr<_Dom1, typename _Dom1::value_type>&, const std::valarray<typename _Dom::value_type>&)’ 414 | _DEFINE_EXPR_BINARY_OPERATOR(>>, struct std::__shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/bits/valarray_after.h:414:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} is not derived from ‘const std::_Expr<_Dom1, typename _Dom1::value_type>’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/valarray:603, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/bits/valarray_after.h:414:5: note: candidate: ‘template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__shift_right, typename _Dom1::value_type>::result_type> std::operator>>(const std::valarray<typename _Dom::value_type>&, const std::_Expr<_Dom1, typename _Dom1::value_type>&)’ 414 | _DEFINE_EXPR_BINARY_OPERATOR(>>, struct std::__shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/bits/valarray_after.h:414:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Dom’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/valarray:1195:1: note: candidate: ‘template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__shift_right, _Tp>::result_type> std::operator>>(const std::valarray<_Tp>&, const std::valarray<_Tp>&)’ 1195 | _DEFINE_BINARY_OPERATOR(>>, __shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/valarray:1195:1: note: template argument deduction/substitution failed: a.cpp:7:18: note: ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} is not derived from ‘const std::valarray<_Tp>’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/valarray:1195:1: note: candidate: ‘template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__shift_right, _Tp>::result_type> std::operator>>(const std::valarray<_Tp>&, const typename std::valarray<_Tp>::value_type&)’ 1195 | _DEFINE_BINARY_OPERATOR(>>, __shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/valarray:1195:1: note: template argument deduction/substitution failed: a.cpp:7:18: note: ‘std::basic_istream<char>::__istream_type’ {aka ‘std::basic_istream<char>’} is not derived from ‘const std::valarray<_Tp>’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95, from a.cpp:1: /usr/include/c++/11/valarray:1195:1: note: candidate: ‘template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__shift_right, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__shift_right, _Tp>::result_type> std::operator>>(const typename std::valarray<_Tp>::value_type&, const std::valarray<_Tp>&)’ 1195 | _DEFINE_BINARY_OPERATOR(>>, __shift_right) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/11/valarray:1195:1: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_Tp’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:51, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.tcc:921:5: note: candidate: ‘template<class _IntType, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::uniform_int_distribution<_IntType>&)’ 921 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~ /usr/include/c++/11/bits/random.tcc:921:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_IntType’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:51, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.tcc:982:5: note: candidate: ‘template<class _RealType, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::uniform_real_distribution<_IntType>&)’ 982 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~ /usr/include/c++/11/bits/random.tcc:982:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_RealType’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:51, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.tcc:2167:5: note: candidate: ‘template<class _RealType, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::cauchy_distribution<_RealType>&)’ 2167 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~ /usr/include/c++/11/bits/random.tcc:2167:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_RealType’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:49, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.h:3722:5: note: candidate: ‘template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::bernoulli_distribution&)’ 3722 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~ /usr/include/c++/11/bits/random.h:3722:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: cannot convert ‘std::endl’ (type ‘<unresolved overloaded function type>’) to type ‘std::bernoulli_distribution&’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:51, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.tcc:1124:5: note: candidate: ‘template<class _IntType, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::geometric_distribution<_IntType>&)’ 1124 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~ /usr/include/c++/11/bits/random.tcc:1124:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_IntType’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:51, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.tcc:1775:5: note: candidate: ‘template<class _RealType, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::exponential_distribution<_RealType>&)’ 1775 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~ /usr/include/c++/11/bits/random.tcc:1775:5: note: template argument deduction/substitution failed: a.cpp:7:18: note: couldn’t deduce template parameter ‘_RealType’ 7 | cin>>number>>endl; | ^~~~ In file included from /usr/include/c++/11/random:51, from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:108, from a.cpp:1: /usr/include/c++/11/bits/random.tcc:2561:5: note: candidate: ‘template<class _RealType, class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::weibull_distribution<_RealType>&)’ 2561 | operator>>(std::basic_istream<_CharT, _Traits>& __is, | ^~~~~~~~教我怎么看编译错误的原因
10-20
#include <iostream> #include <vector> #include <queue> #include <thread> #include <functional> #include <mutex> #include <condition_variable> #include <future> class ThreadPool { public: // 构造函数:初始化线程池,创建指定数量的工作线程 ThreadPool(size_t numThreads) : stop(false) { for (size_t i = 0; i < numThreads; ++i) { workers.emplace_back([this] { while (true) { std::function<void()> task; { std::unique_lock<std::mutex> lock(this->queue_mutex); // 等待任务队列不为空或线程池停止 this->condition.wait(lock, [this] { return this->stop || !this->tasks.empty(); }); // 如果线程池停止且任务队列为空,退出线程 if (this->stop && this->tasks.empty()) { return; } // 取出一个任务 task = std::move(this->tasks.front()); this->tasks.pop(); } // 执行任务 task(); } }); } } // 析构函数:释放所有线程资源,停止线程池 ~ThreadPool() { { std::unique_lock<std::mutex> lock(queue_mutex); stop = true; } condition.notify_all(); // 唤醒所有线程,让它们退出 for (std::thread& worker : workers) { if (worker.joinable()) { worker.join(); // 等待线程结束 } } } // 提交任务到线程池 template<class F, class... Args> auto enqueue(F&& f, Args&&... args) -> std::future<decltype(f(args...))> { using return_type = decltype(f(args...)); auto task = std::make_shared<std::packaged_task<return_type()>>( std::bind(std::forward<F>(f), std::forward<Args>(args)...) ); std::future<return_type> result = task->get_future(); { std::unique_lock<std::mutex> lock(queue_mutex); // 防止任务队列在销毁时被访问 if (stop) { throw std::runtime_error("enqueue on stopped ThreadPool"); } tasks.emplace([task]() { (*task)(); }); } condition.notify_one(); // 通知一个线程来处理任务 return result; } private: std::vector<std::thread> workers; // 工作线程组 std::queue<std::function<void()>> tasks; // 任务队列 std::mutex queue_mutex; // 互斥锁,保护任务队列 std::condition_variable condition; // 条件变量,用于线程同步 bool stop; // 线程池是否停止 }; int main() { ThreadPool pool(4); // 创建一个包含4个线程的线程池 // 提交多个任务 for (int i = 0; i < 8; ++i) { pool.enqueue([i] { std::cout << "任务 " << i << " 正在执行,线程ID:" << std::this_thread::get_id() << std::endl; std::this_thread::sleep_for(std::chrono::seconds(1)); }); } // 主线程等待任务执行完成 std::this_thread::sleep_for(std::chrono::seconds(2)); std::cout << "主线程结束" << std::endl; return 0; } 这个函数的语法 什么的我都不太看的懂啊
09-18
一、 内容概要 本资源提供了一个完整的“金属板材压弯成型”非线性仿真案例,基于ABAQUS/Explicit或Standard求解器完成。案例精确模拟了模具(凸模、凹模)与金属板材之间的接触、压合过程,直至板材发生塑性弯曲成型。 模型特点:包含完整的模具-工件装配体,定义了刚体约束、通用接触(或面面接触)及摩擦系数。 材料定义:金属板材采用弹塑性材料模型,定义了完整的屈服强度、塑性应变等真实应力-应变数据。 关键结果:提供了成型过程中的板材应力(Mises应力)、塑性应变(PE)、厚度变化​ 云图,以及模具受力(接触力)曲线,完整再现了压弯工艺的力学状态。 二、 适用人群 CAE工程师/工艺工程师:从事钣金冲压、模具设计、金属成型工艺分析与优化的专业人员。 高校师生:学习ABAQUS非线性分析、金属塑性成形理论,或从事相关课题研究的硕士/博士生。 结构设计工程师:需要评估钣金件可制造性(DFM)或预测成型回弹的设计人员。 三、 使用场景及目标 学习目标: 掌握在ABAQUS中设置金属塑性成形仿真的全流程,包括材料定义、复杂接触设置、边界条件与载荷步。 学习如何调试和分析大变形、非线性接触问题的收敛性技巧。 理解如何通过仿真预测成型缺陷(如减薄、破裂、回弹),并与理论或实验进行对比验证。 应用价值:本案例的建模方法与分析思路可直接应用于汽车覆盖件、电器外壳、结构件等钣金产品的冲压工艺开发与模具设计优化,减少试模成本。 四、 其他说明 资源包内包含参数化的INP文件、CAE模型文件、材料数据参考及一份简要的操作要点说明文档。INP文件便于用户直接修改关键参数(如压边力、摩擦系数、行程)进行自主研究。 建议使用ABAQUS 2022或更高版本打开。显式动力学分析(如用Explicit)对计算资源有一定要求。 本案例为教学与工程参考目的提供,用户可基于此框架进行拓展,应用于V型弯曲
### 使用 `#include <graphics.h>` 与 Visual Studio 图形处理的对比 #### 头文件和库支持 `#include <graphics.h>` 是 Turbo C/C++ 中的一个头文件,主要用于简单的图形绘制功能[^1]。然而,在现代开发环境中,尤其是像 Visual Studio 这样的集成开发环境 (IDE),通常不直接支持此头文件。 Visual Studio 提供更广泛的支持来处理图形操作,包括但不限于 Windows API、DirectX SDK 或者第三方库如 SFML、SDL 等[^2]。这些工具提供了更为强大和完善的功能集用于创建复杂的视觉效果以及交互式应用程序界面。 #### 功能范围差异 当涉及到具体可以实现哪些型的绘图时: - **简单线条和形状** - 对于基本几何对象(直线、矩形等),两者都能很好地完成任务;但是由于 `<graphics.h>` 的局限性,在复杂度较高的场景下可能显得力有未逮。 - **图像加载显示** - 在展示来自位图或其他格式图片方面,虽然理论上都可以做到这一点,但考虑到跨平台兼容性和性能优化等因素,则推荐采用更加专业的解决方案比如 Direct2D 或 GDI+ 来代替旧式的函数调用方式[^3]。 - **文字渲染** - 文本输出也是常见的需求之一。对于较为基础的需求来说,两种方法都能够满足;不过如果追求高质量的文字呈现效果或是国际化支持的话,则建议利用 Win32 API 下的相关接口来进行定制化配置。 #### 开发体验区别 从开发者角度出发考虑便捷程度及效率问题: - 编译链接过程相对繁琐一些因为需要额外安装并配置对应的驱动程序才能正常使用某些特性; - 而基于 .NET Framework 或其他现代化框架构建的应用则拥有更好的文档资料和技术社区支撑体系,有助于快速解决问题并加速项目迭代进度。 综上所述,尽管 `#include <graphics.h>` 可以为初学者提供一个入门级的学习途径去理解计算机如何工作在底层硬件之上进行画面更新,但对于实际工程项目而言还是应该优先选用由微软官方维护和支持的技术栈作为首选方案以便获得最佳实践指导和服务保障。 ```cpp // Example code using graphics.h in an older environment like Turbo C++ #include <graphics.h> int main() { int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\TC\\BGI"); line(100, 100, 400, 400); getch(); closegraph(); } ``` ```csharp using System.Windows.Forms; namespace SimpleGraphicsApp { public partial class MainForm : Form { public MainForm() { InitializeComponent(); Paint += new PaintEventHandler(DrawOnForm); } private void DrawOnForm(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen pen = new Pen(Color.Black); // Drawing a line as example g.DrawLine(pen, 100, 100, 400, 400); } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值