Hello.
I was wondering if i can choose from a text file with numbers inside the number i want exactly. For example the numbers are in 5 lines.:
5
3
6
2
7
Can i choose what to show? I want to show up only the number 2 or 7 or 3!
Is there any way to do that????
int g[]; //you need to give this array an explicit size
ifstream f;
f.open("data.txt");
if(f.is_open());
{
f>>a;
//no closing brace for this if statement
for(int i=0; i<a; i++)
{f>>g[];} //you need to index that array
cout<<g[i]; // this is outside the for loop. i is local to the for loop, so this won't compile.
if you are looking for one specific number and you want to print it out when you find it, just put an if statement inside the for loop that will print g[i] when g[i] == the number you want
All i want is to do a bubble sort in this txt file.
And i dont now how exactly.And i think this way will help me.If i find how to do that i will continue i think.And i searched the forum for the bubble sort but i didnt find some good tutorials with fstream.
it doesn't matter whether you're reading from a file or not. just read the contents of the file into your array and run the array through a bubble sort.