Wrint Input File to Screen

Hi. I have tried everythin in my limited C++ knowledge to write the input file to the screen. I've also tried to "cout" the output.To no avail.
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 <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;

const int invSize = 2;

void getInventory (ifstream& infile, vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
  vector<int> pInStore, vector<int> pSold, vector<double> manufPrice, vector<double> sellingPrice); 
     
     int main() 
{
	
/*	vector<int> itemQuantity;    */
	vector<string> itemID;
	vector<string> itemName;
	vector<int> pOrdered;
	vector<int> pInStore;
	vector<int> pSold;
	vector<double> manufPrice;
	vector<double> sellingPrice;
	
	ifstream infile;

	infile.open("I:\\inventory.txt");
	if (!infile)
	{
		cout << "Input file (inventory.txt) does not exsit." << endl;
		system ("pause");
		return 1;
	}

	getInventory(infile, itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);

	infile.close();
    system ("pause");
	return 0;
}

void getInventory(ifstream& infile, vector<string> itemID, vector<string> itemName, vector<int> pOrdered, 
				 vector<int> pInStore, vector<int> pSold, vector<double> manufPrice, 
				 vector<double> sellingPrice) 

cout << endl:
     cout << itemID << endl;


Error Msg.
expected init-declarator before "cout"
expected `,' or `;' before "cout"
Use cerr << "blah" << '\n'; instead for line 31.


The errors here are so simple.

On line 47, you need to end it with a semi-colon.

Please read your code before sending this stuff in.
Thank you, Ben.
Ahhh... but I did READ my code B4 sending it in. Maybe I should've taken a break AND then re-read it B4 sending it in. :-) I appreciate your help.
Yeah, sorry if I sounded a bit harsh there. I was tired and grumpy... A Red Bull and I'm back to normal. Glad to help.
Well, now that you've had that Red Bull I will venture to ask you another question in the same realm. Error msg:

In function `void getInventory(std::ifstream&, std::vector<std::string, std::allocator<std::string> >,
" ))<< itemID'.
I don't know if the second line of err msg is a part of the 1st line of err msg.

I really, really did read "this stuff" :-) B4 I sent it in.

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;

const int invSize = 2;

void getInventory (ifstream& infile, vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
  vector<int> pInStore, vector<int> pSold, vector<double> manufPrice, vector<double> sellingPrice); 
     
     int main() 
{
	
/*	vector<int> itemQuantity;    */
	vector<string> itemID;
	vector<string> itemName;
	vector<int> pOrdered;
	vector<int> pInStore;
	vector<int> pSold;
	vector<double> manufPrice;
	vector<double> sellingPrice;
	
	ifstream infile;

	infile.open("I:\\inventory.txt");
	if (!infile)
	{
		cout << "Input file (inventory.txt) does not exsit." << endl;
		system ("pause");
		return 1;
	}

	getInventory(infile, itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);

	infile.close();
	return 0;
    
}

void getInventory(ifstream& infile, vector<string> itemID, vector<string> itemName, vector<int> pOrdered, 
				 vector<int> pInStore, vector<int> pSold, vector<double> manufPrice, 
				 vector<double> sellingPrice) 
{
	unsigned int i;
	string line;

	for (i = 0; i < itemID.size(); i++)
	{
		infile >> itemID[i] 
			   >> itemName[i] 
			   >> pOrdered[i] 
			   >> pInStore[i]
			   >> pSold[i]
			   >> manufPrice[i] 
			   >> sellingPrice[i] ;
    
    }
    
     cout << endl;
     cout << "Item ID:  " <<itemID<< ;
     return;
     
}

You have to write cout << "Item ID: " <<itemID<<endl; instead of cout << "Item ID: " <<itemID<< ; in line 63. And you don't have to write return; into a function which returns nothing
1
2
3
4
void getInventory (...)
{
      ...
}

void means that a function CAN NOT return something. Therefore is using a return statement (return;) useless.
Last edited on
Many, many thanks FlashDrive. What a great group.
Isoldeold
You're welcome ;)
Topic archived. No new replies allowed.