Trouble reading text file

I'm a college student looking for help :(

my project includes opening and reading a text file ("customers.txt").
this is my text file:

6
Joe
P 10.02 Y
Mary
r 15.50 N
Dan
U 19.00 y
Victoria
R 6.50 y
Nick
n 0 Y
Vigo
p 18.27 N


I wrote this code, but it seems not to find the text file or maybe some other problem. please help :(


#include <iostream>
#include <fstream>

using namespace std;

int main()
{
ifstream inputFile;
int number;
int count = 1;
inputFile.open("customers.txt");
if (!inputFile)
cout << "Error!!!\n";
else
{
while (count <= 13)
{
inputFile >> number;
cout << number << endl;
count++;
}
inputFile.close();
}

return 0;
}
Last edited on
Hello?
> but it seems not to find the text file

Give the complete path to the file. For example:
"/usr/home/BlueOrca/devel/data/customers.txt" (Unix)
"C:\\Documents and Settings\\BlueOrca\\Desktop\\numbers.txt" (Windows)

Test the path by running this program; if the path is correct the contents of the file will be dumped on stdout.

1
2
3
4
5
6
7
8
#include <iostream>
#include <fstream>

int main()
{
    const char path[] = "<put the complete path to the file here>" ;
    std::cout << std::ifstream(path).rdbuf() ;
}
sorry I'm beginning C++ I copied your code and got these errors:



line 6 error: incomplete universal character name \U
line 6 warning unknown escape sequence '\B' [enabled by default]
line 6 warning unknown escape sequence '\D' [enabled by default]
Last edited on
"C:\\Documents and Settings\\BlueOrca\\Desktop\\numbers.txt"

Did you use double slashes?
where should I go to enter this path?
const char path[] = "<put the complete path to the file here>" ;


read the code he provided to you ^^^^^^^^^^^
Topic archived. No new replies allowed.