What is wrong with my code? "no match for 'operator>>' error.

Here is the error message I keep getting:
p2.cpp: In function `void outputResults(std::ifstream&, int&, int&, std::string**)':
p2.cpp:88: error: no match for 'operator>>' in 'std::cout >> "Filename: "'
p2.cpp:89: error: no match for 'operator>>' in 'std::cout >> "Number of lines: "'
p2.cpp:90: error: no match for 'operator>>' in 'std::cout >> "Number of characters: "'
p2.cpp:91: error: no match for 'operator>>' in 'std::cout >> "Words: "'
p2.cpp:91: error: expected primary-expression before ']' token

At first the error message said "p2.cpp: In function `void outputResults(std::ifstream&, int&, int&, std::string*)'"
I thought it was because I originally didn't have an "*" after the word "string", but now that I added the "*", it added 2 "*"'s to the error message. Gah! What am I doing wrong!?!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>
#include<fstream>
#include<string>
using namespace std;

// Function Prototypes
void readFilename(ifstream&, string&);
void countCharsLines(ifstream&, int&, int&, char&);
void populateArray(ifstream&, string[]);
void outputResults(ifstream&, int&, int&, string[]);

int main()
{
  // Variables
  ifstream inFile;
  string filename;
  int countLines;
  int countChars;
  char ch;
  string words[1000];

  // Function Calls
  readFilename(inFile, filename);
  countCharsLines(inFile, countLines, countChars, ch);
  populateArray(inFile, words);
  outputResults(inFile, countLines, countChars, words);
  return 0;
}
// THIS IS THE FUNCTION WITH AN ISSUE!
void outputResults(std::ifstream &inFile, int &countLines, int &countChars, std::string* words[])
{
  cout >> "Filename: " >> inFile >> endl;
  cout >> "Number of lines: " >>countLines >> endl;
  cout >> "Number of characters: " >> countChars >> endl;
  cout >> "Words: " >> words[] >> endl;
}
ofstream needs << not >>. They are simply going the wrong way.

1
2
3
4
5
6
7
void outputResults(std::string &filename, int &countLines, int &countChars, std::string* words[])
{
  cout << "Filename: " << filename << endl;
  cout << "Number of lines: " <<countLines << endl;
  cout << "Number of characters: " << countChars << endl;
  cout << "Words: " << words[] << endl;
}
OMG really? I had it like that originally but then for some reason I changed it thinking it was wrong. UGH! Thank you!
Now it's giving me this output error:
p2.cpp: In function `void outputResults(std::string&, int&, int&, std::string**)':
p2.cpp:91: error: expected primary-expression before ']' token

Notice it says "std::string**" with 2 "*"s, originally it said
p2.cpp: In function `void outputResults(std::string&, int&, int&, std::string**)':
p2.cpp:91: error: expected primary-expression before ']' token
with only 1 "*". So what else am I missing? Here is my updated function code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

// Function Prototypes
void readFilename(ifstream&, string&);
void countCharsLines(ifstream&, int&, int&, char&);
void populateArray(ifstream&, string[]);
void outputResults(string&, int&, int&, string[]);

int main()
{
  // Variables
  ifstream inFile;
  string filename;
  int countLines;
  int countChars;
  char ch;
  string words[1000];

  // Function Calls
  readFilename(inFile, filename);
  countCharsLines(inFile, countLines, countChars, ch);
  populateArray(inFile, words);
  outputResults(filename, countLines, countChars, words);
  return 0;
}

// FUNCTION WITH ISSUES
void outputResults(std::string &filename, int &countLines, int &countChars, std::string* words[])
{
  cout << "Filename: " << filename << endl;
  cout << "Number of lines: " << countLines << endl;
  cout << "Number of characters: " << countChars << endl;
  cout << "Words: " << words[] << endl;
}
Declaration:
void outputResults(string&, int&, int&, string[]);

Definition:
void outputResults(std::string &filename, int &countLines, int &countChars, std::string* words[])

Notice any difference?
Nevermind i figured it out the delcaration & definition are fine, when it came to the function of "outputResults" I had to change the definite to (string &filename, int &countlines, int &countchars, string words[]) then within the function had brackets when i went to output "words" so instead of "words[]" it was supposed to be "words" ugh stupid me making stupid mistakes.
Topic archived. No new replies allowed.