Hello there.
I'm trying to make a program which can input elements (integers) and sort them, then input them in a txt file.
I've made the functions (write on file, read from file, sorting elements), but now I need the following..

When I use a file on which I have unsorted numbers, when I open this file the elements from the txt file to be called in to something (array or pointer.. I don't know) and to call the sorting function. Then after sorting I need to write the elements back in the file.

The problem is that I don't know how to take the elements and convert them into an integer.
Can someone help me or give me info?

Can someone help me or give me info?

Open your book to the chapter on I/O and read it. If you don't understand how to read an integer from input, that's the first step.

Open your book to the chapter on I/O and read it. If you don't understand how to read an integer from input, that's the first step.

I don't think you've got the point.

I don't think you've got the point.

Dude, the very first I/O example in every C++ book I can recall is:

int x;

cin >> x;

Now do that with a file stream:

ifstream in("myfile");
int x;

in >> x;

Done. I posit that because you didn't understand how to do that, you need to read your freaking C++ book and learn the most basic of basics.

Dude, the very first I/O example in every C++ book I can recall is:

int x;

cin >> x;

Now do that with a file stream:

ifstream in("myfile");
int x;

in >> x;

Done. I posit that because you didn't understand how to do that, you need to read your freaking C++ book and learn the most basic of basics.

Dude listen.
When I have a file with already inputed elements, and I want to read it, but if it is not sorted, to take the elements and sort them and then input them back in the file.
I need to take the files in an array.
Not just read them.

Unless your communication skills are weaker than your programming skills, you want to read the numbers in a file into an array, sort them, then overwrite the file with the sorted numbers.

This doesn't change how you read from a file stream:

ifstream in("file");
vector<int> v;
int x;

while (in >> x) {
    v.push_back(x);
}

// sort the vector

// write the file

Stop trying to act like I don't understand what you want.

Unless your communication skills are weaker than your programming skills, you want to read the numbers in a file into an array, sort them, then overwrite the file with the sorted numbers.

This doesn't change how you read from a file stream:

ifstream in("file");
vector<int> v;
int x;

while (in >> x) {
    v.push_back(x);
}

// sort the vector

// write the file

Stop trying to act like I don't understand what you want.

Well yes my programming skills are weak.
I'm not proud about it, but I won't get any better you you're telling me that "I'm acting that you don't uderstand".
I wanted to say that, you didn't get the point of my words.
So if you don't have the patients to help a beginner like me, just don't!
Anyway thank you for the help!

I'm not proud about it, but I won't get any better you you're telling me that "I'm acting that you don't uderstand".

You won't get any better by ignoring legitimate help either. I still don't see any evidence that my initial suggestion was wrong, despite your insistence that I "didn't get the point" of your words. You won't get any better by being lazy, and failing to do the most basic of study before running for help certainly looks like laziness to me.

So if you don't have the patients to help a beginner like me, just don't!

My patients don't assist me with helping beginners.

Anyway thank you for the help!

That's all the help you can expect from me. Given your attitude thus far, I won't waste my time in the future.

You won't get any better by ignoring legitimate help either. I still don't see any evidence that my initial suggestion was wrong, despite your insistence that I "didn't get the point" of your words. You won't get any better by being lazy, and failing to do the most basic of study before running for help certainly looks like laziness to me.


My patients don't assist me with helping beginners.


That's all the help you can expect from me. Given your attitude thus far, I won't waste my time in the future.

I see..
You really don't understand.
I wanted to thank you for the help.
And I wanted to say that for the future, you should ignore the people who ask stupid questions.
I don't want to say something against you.
And don't get this wrong.
I have never asked for your help, so don't be so critic.
Anyway.. Sorry for the useless chat that I've made.
And btw nice avatar..

Hi Nimerion,
Your original problem was:

The problem is that I don't know how to take the elements and convert them into an integer.

I assume you have a text-file with a bunch of integers in it. Is the problem that you don't know how to read the strings out of the text-file? Or that you don't know how to convert each string into an integer so you can easily compare and sort them? Or am I -also- not understanding the details of the problem.

It is reasonably clear that English isn't your primary language. Unfortunately it -is- the primary language used for communicating on this forum. Telling any of us (let alone Narue, with over 11000 posts in this forum since 2004) that we don't understand you ... that isn't helping. Obviously we don't understand you. But that doesn't make us or you stupid. Instead, try again to clarify what you're talking about. Maybe with a small example of the file or files in question. And definitely post the code you've written so far, along with specific questions about how to fix errors or implement additional features.

Also, don't forget to enclose your code in [ CODE ] tags. Select it all with the mouse, and click the [ CODE ] icon at the top of the editor. See how all that does is put "[ CODE ]" in front of your code, and "[ /CODE ]" after it (without the embedded spaces). You could just as easily hand-type those tags.

Member Avatar for jtbens01

This forum is supposed to be for help. Do not bash on people trying to get help.

commented: Self-declared net nannies need not apply -4
commented: bad idea for your first post in a forum to be telling other people, especially the most senior members of the forum, what to do -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.