简体   繁体   English

(错误)'std :: cout >> namesArray(counter)(0)'中的'operator >>'不匹配

[英](Error) no match for 'operator>>' in 'std::cout >> namesArray(counter)(0)'

I'm really lost as to why I'm getting an error for this particular array index. 我真的迷失了为什么我对这个特定的数组索引出错。 I'm writing a program that takes student grades input from a text file. 我正在编写一个程序,该程序需要从文本文件输入学生成绩。 This file is 10 rows of 2 columns in the format (FirstName, LastName, Grade 1, Grade 2, Grade 3, Grade 4, Grade 5). 该文件是10行,每行2列,格式为(名字,姓氏,等级1,等级2,等级3,等级4,等级5)。 During execution I need to loop through the file line by line and put the names into their own 10 rows by 2 columns and put the grades in their own 10 rows by 5 columns. 在执行期间,我需要逐行遍历文件,并将名称放入自己的10行乘2列,并将成绩放入自己的10行乘5列。 It's a class thing, Idk why we are doing it that way. 这是一个阶级问题,Idk我们为什么要这样做。 Basically the data will split and loaded into a namesArray and gradesArray during the loop. 基本上,数据将在循环期间拆分并加载到namesArray和gradesArray中。 I've marked the error line identified in my IDE with * on either side and at the line positions 我已经在IDE中标识的错误行的两侧和行位置都标有*

Finally, here is my code: 最后,这是我的代码:

//Student Name:  Jacob Gillespie
//Date:  10/20/13
//Program:  Student Grade Manipulation
//Summary:  Reads in grade data from text file, manipulates data
//and stores data back in output file

//Headers
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

//Declare variables and arrays
ifstream inData;
ofstream outData;

string namesArray[10][2];
string gradesArray[10][5];



//Main Program Execution

int main()

{
//Open the data file containing the student names and grades
inData.open("StudentGrades.txt");

//Read data lines and assign student names to namesArray and grades to gradesArray
for (int counter = 0; counter < 10; counter++)
    inData >> namesArray[counter][0] >> namesArray[counter][1]
           >> gradesArray[counter][0] >> gradesArray[counter][1] >> gradesArray[counter][2]
           >> gradesArray[counter][3] >> gradesArray [counter][4];

//TESTING, Print namesArray and gradesArray to ensure values are loaded and assigned correctly
for (int counter = 0; counter < 10; counter++)
    *****cout >> namesArray[counter][***0***] >> " " >> namesArray[counter][1] >> endl;*****

for (int counter = 0; counter < 10; counter++)
    cout  >> gradesArray[counter][0] >> " " >> gradesArray[counter][1] >> " " >> gradesArray[counter][2]
          " " >> gradesArray[counter][3] >> " "gradesArray [counter][4] >> endl;

return 0;
}
cout >> ... >> .. >> ...;

should be 应该

cout << ... << .. << ...;

Think about putting data into an output stream, thus the data should go towards it. 考虑将数据放入输出流,因此数据应该流向输出流。

The operator of cout as an output stream is << . cout作为输出流的运算符是<<

  +--------+                
  |        |                
  |  cout  | <<-----  data  
  |        |                
  +--------+                

  +--------+                
  |        |                
  |  cin   | ----->>  data  
  |        |                
  +--------+     

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:“std::cout”中的“operator&lt;&lt;”不匹配 - ERROR: no match for 'operator<<" in 'std::cout 错误:在std :: cout中没有匹配operator &lt;&lt;(我已经重载了&lt;&lt;运算符) - Error: no match for operator << in std::cout (I have already overloaded the << operator) 错误:std :: operator &lt;&lt;中的operator &lt;&lt;不匹配 <std::char_traits<char> &gt;(**&std :: cout),(((const char *) - error: no match for operator<< in std::operator<< <std::char_traits<char> >(*&std::cout),((const char*) &#39;std :: cout &lt;&lt; :: operator ++(int)(0)&#39;中&#39;operator &lt;&lt;&#39;不匹配 - no match for 'operator<<' in 'std::cout << ::operator++(int)(0)' 比较 std::ostream 以查看它是否为 std::cout(“不匹配 &#39;operator==&#39;”) - Compare std::ostream to see if it is std::cout ("no match for 'operator=='") 错误:当我串流到cout时,与&#39;operator &lt;&#39;不匹配 - error: no match for ‘operator<’ when I stream to cout Cout 不起作用 - (错误:“运算符&lt;&lt;”不匹配) - Cout does not work - (error: no match for ‘operator<<’) 为什么M :: operator &lt;&lt;导致链接错误而不是std :: cout :: operator &lt; - Why M::operator<< causes a link error instead of std::cout::operator<< 为什么要写一个std :: string给cout导致一个未知的运算符<<错误? - Why is writing a std::string to cout causing an unknown operator << error? 减少 std::cout 中的 &lt;&lt; 运算符链 - Reduce << operator chain in std::cout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM