问题描述
我是一个完整的初学者,并且我一直在看这段代码两天了,但我一直想不通自己所做的工作,不断产生此错误消息:
main.cpp: In function ‘int main()’:
main.cpp:19:43: error: no match for ‘operator>>’ (operand types are ‘std::basic_ostream<char>’ and ‘const char [25]’)
value of num1 =" << num1 >> " and the value of num2 " << num2 >> ".";
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/string:53:0,from /usr/include/c++/7/bits/locale_classes.h:40,from /usr/include/c++/7/bits/ios_base.h:41,from /usr/include/c++/7/ios:42,from /usr/include/c++/7/ostream:38,from /usr/include/c++/7/iostream:39,from main.cpp:1:
/usr/include/c++/7/bits/basic_string.tcc:1465: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,_Alloc>&)
operator>>(basic_istream<_CharT,_Traits>& __in,^~~~~~~~
/usr/include/c++/7/bits/basic_string.tcc:1465:5: note: template argument deduction/substitution failed:
main.cpp:19:46: note: ‘std::basic_ostream<char>’ is not derived from ‘std::basic_istream<_CharT,_Traits>’
lue of num1 =" << num1 >> " and the value of num2 " << num2 >> ".";
^~~~~~~~~~~~~~~~~~~~~~~~~~
#include <iostream>
#include <string>
using namespace std;
int main()
{
//variable declaration
int num1,num2,newNum,SECRET;
SECRET = 11;
double RATE = 12.50;
string name;
double hoursWorked,wages;
//executable statements
cout << "Give me two integers";
cin >> num1 >> num2;
cout << "The value of num1 =" << num1 >> " and the value of num2 " << num2 >> ".";
newNum = (num1*2)+num2;
cout<< "The new value of newNum =" << newNum;
newNum = newNum+ SECRET;
cout<< "The new value of newNum =" << newNum;
cout << "What's your last name?";
cin >> name;
cout << "Enter a decimal number between 0 and 70";
cin >> hoursWorked;
wages = RATE*hoursWorked;
cout << "Name: " << name << "\n" << "Pay Rate: $" << RATE << "\n" << "Hours Worked: "<<hoursWorked << "\n" << "Salary: $ " << wages;
return 0;
}
解决方法
您使用了错误的运算符:
if ($request->get('q')) {
$q = $request->get('q') ? urldecode($request->get('q')) : null;
$products->where('title','LIKE',"%{$q}%");
}
$products->with(['categories' => function($query) use ($filter_ids) {
// Query for active categories
$query->where('active',1)->whereHas('filters',function ($query) use ($filter_ids) {
// Query for the selected filters from the request
$query->whereIn('id',$filter_ids);
});
}]);
$response = $products->limit(10)->get();
return response()->json([
'status' => 'success','response' => $response
],200);
您应该使用过:
// cout << "The value of num1 =" << num1 >> " and the value of num2 " << num2 >> ".";
// here ^ and here ^
,
#include <iostream>
#include <string>
using namespace std;
int main()
{
//variable declaration
int num1,num2,newNum,SECRET;
SECRET = 11;
double RATE = 12.50;
string name;
double hoursWorked,wages;
//executable statements
cout << "Give me two integers";
cin >> num1 >> num2;
cout << "The value of num1 =" << num1 << " and the value of num2 " << num2 << ".";
newNum = (num1*2)+num2;
cout<< "The new value of newNum =" << newNum;
newNum = newNum+ SECRET;
cout<< "The new value of newNum =" << newNum;
cout << "What's your last name?";
cin >> name;
cout << "Enter a decimal number between 0 and 70";
cin >> hoursWorked;
wages = RATE*hoursWorked;
cout << "Name: " << name << "\n" << "Pay Rate: $" << RATE << "\n" << "Hours Worked: "<<hoursWorked << "\n" << "Salary: $ " << wages;
return 0;
}
即使正在打印变量,也不要在cout中使用“ >>”。那是一个简单的语法错误。