#Read a File
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

What is the name of the file?
Names.csv
And is that what you input to the program?
Im sorry after rechecking it says Names
It must be Names.txt
Hmmm when I open the file that my teacher had me download it opens excel
With the names
here
So is a csv?
Ok I probably explained this badly. When I click to down the file it says csv, but when I see it on the file, it says names. Does that matter?
It also tells the type of the file in explorer
Right to the name of the file
It says Excel in explorer
Input "Names.csv" to your progran
Ok one second
Without double quotes
Sorry this class is introduction to C++ and our class has to use visual studio
Well thank god
Its not dev c++
So did you enter the name of the file when your program asks for the input?
Yes but now there are errors and im not understanding what happened
Im checking if I hit a key I shouldn't have somewhere
Oh I see one second
You should just hardcode the name in the program, not ask for it in input as asshullbreaker mentioned.
How would I do that then?
change infile.open(Names); to infile.open("Names.csv"); and remove getline above it
And also
The Names.csv should be next to your program exe or working directory
Remove the getline line entirely
That is easy to get around
First of all open the damn file, im sure it won't be easy cuz of visual studio
No, did you run your program?
Copy it to the project directory
This outputs shows where that is 2 lines below
No in the folder where your .cpp file is located, copy it there
Ok done
Now run
Lets move to the next problem
ok
The names are separated by ','
You have to, as he said replace , with newline
Not really, you have to keep printing the character until you see that the character is comma, if its a comma dont print it instead print '\n' in its place, do you know how to do that?
No sorry
Do you know what part of your code prints the file(names)?
No
Giving you the solution directly will be spoon-feeding now, so maybe you should go through your code a line at a time, and figure out what exactly it is doing, otherwise you will learn nothing.
No, it makes the names in std namespace visible globally, so you dont have to type std::cout, std::getline etc, but its a bad practice to put using namespace std
Start from int main()
Would this be it? while (infile.get(c)) // Read and print each character from the file... Remembering from the video it reads each character correct?
Yes, this is what reads each character one at a time from the file
And what prints the character to the console?
cout
The character that is read from the file is stored in c defined above this while loop as char c;
Yes
You can check the value of c, if its ',' then print the newline
Went back to another video for a second that was like this but is it suppose to be like this?
My teacher doesn't really have any videos on the class so im just researching what I can and trying to take notes at the same time
while not confusing myself
I found some helpful YouTube videos that explain c++ really well but get lost easily
Uh but however can I ask that we stop because it almost 3 here
Sorry and thank you
Ditch the videos get the book
No worries and no problem
Do you want me to close this and open another one? Or do you want me to leave this open when I come back
I guess its solved
Ok then
What is ifstream? A decoration for file operations to can use ??
Its an input file stream, a file from which you extract data
I believe that header is used to read files if im not mistaken
Oh okay tyy ! <33
Nightt
!solved