2015-07-02 54 views
1

我有一個賦值,我們應該使用cstrings而不是字符串。問題在於五個cout語句中的三個中的操作數爲<。任何人都可以幫我弄清楚如何讓操作數錯誤消失嗎?該代碼發佈如下。錯誤位置以粗體列出!謝謝!cstring <<找不到操作符的類型爲'std :: string'的右手操作數

#include <iostream> 
#include <cstring> 
#include <cstdlib> 
using namespace std; 

int main() 
{ 

int strLength, wPointer; 
string custNumber, year, workOrderNumber; 

string workOrder = "91800w940770"; 

strLength = workOrder.length(); 
wPointer = workOrder.find('w', 0); 
custNumber.assign(workOrder, 0, wPointer); 
year.assign(workOrder, wPointer + 1, 2); 
workOrderNumber.assign(workOrder, wPointer + 3, strLength); 

cout << "The length is " << strLength << endl; 
cout << "The location of the w is " << wPointer << endl; 
std::cout << "The customer number is " **<<** custNumber << std::endl; 
cout << "The year of the order is " **<<** year << endl; 
cout << "The order number is " **<<** workOrderNumber << endl; 

system("pause"); 
return 0; 

} 

回答

0

custNumber,year和workOrderNumber是字符串。

包括<string>使用它們與< <運營商。

0

庫「< <」函數在std :: strings上不起作用。您可以創建自己的函數,以便一次輸出字符串中的字符一個字符

相關問題