working with txt files

hello friends, trying to understand a little work with txt, and in c + +, the file I can not open and goes straight to the end, what will my mistake
the file is called nombres.txt and contains
carlos, alberto, raul, tomas,

and the code is
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
#include<iostream>
#include<fstream>
#include<string>

using namespace std;

int main()
{
	string linea;
	string nombre;
	char a=',';
	cout<<"ingrese el nombre buscado"<<endl;
	getline(cin, nombre);
	ifstream miArchivo ("nombres.txt");
	if (miArchivo.is_open())
	{
		while (getline(miArchivo, linea,a ))
		{
			if (nombre==linea)
			{
				cout<<"el nombre buscado esta presente "<<endl;
			}
			else
			{
				cout<<"el nombre no esta"<<endl;
			}
		}
		miArchivo.close();
	}
	else
	{
		cout<<"algo paso"<<endl;
	}
	getchar();
	return 0;
}
Are you running the program in the same place as the txt file?
yes, I put the txt in the same place

good day to all, yesterday in a moment of sleep, I realized something very important, "the location of the txt", ok not the most excellent code but it works.
As input for those using visual c + +, when they make a console project like 20 folders and no one knows where it goes the famous txt, so here a picture for you to know where it is located

http://subefotos.com/ver/?94d6783d5797d33fdbc1df50266b18a7o.jpg
Last edited on
Topic archived. No new replies allowed.