Having trouble opening an input file

closed account (oN3k92yv)
Whenever I run it with what I have so far, I always get cannot open input file, program terminates!

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

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <sstream>

using namespace std;


int main()
{
	string tool;
	double unitCost;
	double numberOfUnits;
	double totalCost;
	int counter; 

	ifstream inFile;
	ofstream outFile;
	
	inFile.open("inventory.txt");

	if (!inFile)
	{
		cout << "Cannot open input file. Program Terminates! " << endl; 
		return 1;
	}

	outFile.open("inventory.out");
	outFile << fixed << showpoint << setprecision(2);

	inFile >> tool >> numberOfUnits >> unitCost;
	
	for (int i = 0; i < 6; i++);

	while (inFile) 
	{
		for (int i = 0; i < 6; i++);
		totalCost = numberOfUnits * unitCost;
	

	}

	
	
	
} 
Well, pretty much means you have misplaced and/or misnamed your file. You have to place it with your main.cpp and where your .vcxproj is, if you're just gonna use "inventory.txt".

Take a look at this video - https://www.youtube.com/watch?v=HcONWqVyvlg&list=PLAE85DE8440AA6B83&index=64
Your code has a couple of syntax error (line 35, line 39). However, to answer your question. I created a file "inventory.txt" and placed it in the same place as the main.cpp and it reads the file. Could you tell us what the program is supposed to do?
closed account (oN3k92yv)
How do you place the file in the main.cpp? I'm trying to make a program that will read and sort the inventory of a file
@ aixth, TarikNeaj answered your question about the placement of your file. Take a look at the link video he provided. Good luck
Topic archived. No new replies allowed.