file open error

I am getting an error with the in.open section, it is telling me I cannot convert from a float to a stream, any insight?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
#define Length 150
ifstream in;

float Anumber[Length];

int main()
{
	float file;
	
	cout << "please enter the location of the file" << endl;
	cout << "an example would be C:/my file.txt" << endl;
	cin >> file;
	
	in.open(file);
	if (!in)
	{
		cerr << "Error file not found" << endl;
		exit(1);
	}
Edit: Misread the code. The file name is obviously a string, not a number right?

string file;
Last edited on
So then how would I allow the user to enter the file location?
The file name in this case is numbers.txt
closed account (2LzbRXSz)
"C:/my file.txt" is an example of a string.
I now see the error that I'm trying to make a file type of float allow a char to be entered. But that still doesn't fix my problem. But thank you for point that out.
Change it from float to string. And use getline(cin, file); instead of cin >>
closed account (2LzbRXSz)
What error is it giving you now?
Thanks that did it, your awesome!
You're welcome^^
Topic archived. No new replies allowed.