cannot get it to run right.

Just trying to print out one line for a spreadsheet where I will eventually have five.Getting error: no match for 'operator<<' in 'std::cout << rowOne'

#include <iostream>
#include <vector>

using namespace std;


vector <int>rowOne(5);
void clear (vector<int>& someRow);
void print (vector<int>& someRow);

int main()
{
cout << "Chris's Spreadsheet" << endl;
{
clear (rowOne);
print(rowOne);
}
return 0;

}

void clear (vector<int>&someRow)
{
for (int i=0; i<someRow.size();i++)
someRow[i] = 0;
}

void print (vector<int>&someRow)
{
cout << rowOne;
for (int i=0; i<someRow.size();i++)
someRow[i] = 0;
cout << endl;
}
closed account (z05DSL3A)
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
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <vector>

#include <algorithm>  //Added

using namespace std;


vector <int>rowOne(5);
void clear (vector<int>& someRow);
void print (vector<int>& someRow);

void printElement (int i)  //Added
{
  cout << " " << i;
}

int main()
{
    cout << "Chris's Spreadsheet" << endl;
    {
        clear (rowOne);
        print(rowOne);
    }
    return 0;

}

void clear (vector<int>&someRow)
{
    for (int i=0; i<someRow.size();i++)
        someRow[i] = 0;
}

void print (vector<int>&someRow)
{
    //cout << rowOne;  //Can't do this with a vector Try:
    for_each (rowOne.begin(), rowOne.end(), printElement);
    //or
    for (int i=0; i < rowOne.size(); i++)
        cout << rowOne[i]  << " ";
    cout <<endl;


    for (int i=0; i<someRow.size();i++)
        someRow[i] = 0;
    cout << endl;
}
Last edited on
I think in your print function you mean to use someRow instead of rowOne. In any case, the reason for the error is that cout cannot print a vector. You will have to manually iterate through and print each value yourself.

EDIT: Damn, Grey Wolf beat me too it. xD
Last edited on
closed account (z05DSL3A)
I think in your print function you mean to use someRow instead of rowOne.

I hadn't even noticed that, time to sleep I think. ;0)
Hmm using rowOne should still work, ain't it? The vector has been declared globally...

CRBottini, you should declare your vector in main(), or else it's quite pointless to pass it to your print function as rowOne. It's good programming practice to avoid using global variables too.
Thanks Guys, big help. Now I am trying to get labels for the rows and colums. Numbers for the rows, letters for the columns. kind of like how excel does it. Put in bold what I added to the code. Getting some errors. Do not even know if i'm taking the right steps.

#include <iostream>
#include <vector>

using namespace std;


vector <int>rowOne(5);
vector <int>rowTwo(5);
vector <int>rowThree(5);
vector <int>rowFour(5);
vector <int>rowFive(5);
void clear (vector<int>& someRow);
void print (vector<int>& someRow);
void printAll
int rowLabel


int main()
{
cout << "Chris's Spreadsheet\n" << endl;
{
clear (rowOne);
clear (rowTwo);
clear (rowThree);
clear (rowFour);
clear (rowFive);
print(rowOne);
print(rowTwo);
print(rowThree);
print(rowFour);
print(rowFive);
}
return 0;

}
void printAll (int rowLabel)
{
rowLabel = 1;
int rowLabel = 0;

for (int i=0; i<5, i++)
rowLabel = ++;
cout << rowLabel

}
void clear (vector<int>&someRow)
{
for (int i=0; i<someRow.size();i++)
someRow[i] = 0;
}

void print (vector<int>&someRow)
{
for (int i=0; i < rowOne.size(); i++)
cout << rowOne[i] << " ";
cout <<endl;


for (int i=0; i<someRow.size();i++)
someRow[i] = 0;
cout << endl;

}
Topic archived. No new replies allowed.