الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

read a text file

بدأه زهرة تشرين في 14 أكتوبر 2010 · 3 رد · 451 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

That read a text file and then extract it's words and store them in another text file each words in a separates line

ارجو المساعده ضروري

#2

جربى هذا الكود::::::::::

#include <iostream.h>
#include <fstream.h>
void main ()
{
	// opening the source file
	ifstream file1 ("f1.txt",ios::binary);
	if (!file1)
	{
		cout<<"cannot open file";
		return;
	}

// creating the destination file
	ofstream file2 ("f2.txt",ios::binary);
	if (!file2)
	{
		cout<<"can not create file";
		return;
	}

	char ch;
	while (!file1.eof())
	{
		file1.get(ch);
		if(ch==' ' ){
		cout<<endl;
		}
		file2.put(ch);
	}
	file1.close();
	file2.close();
}

و لا تنسى ان تضعى المسار الصحيح للملف تبعك....بالتوفيق

تم تعديل هذه المشاركة بواسطة نفرتاري في 14 أكتوبر 2010 في 21:15

00020309t.gif

1958_1963.gif
#3

انا ممكن اشرح الكود..لو محتاجة :)

00020309t.gif

1958_1963.gif
#4
#include <fstream>
#include <string>
#include <iterator>
#include <algorithm>
using namespace std;

typedef istream_iterator<string> input_i;
typedef ostream_iterator<string> output_i;

int main()
{
	ifstream input_file("input.txt");
	ofstream output_file("words_list.txt");
	copy(input_i(input_file), input_i(), output_i(output_file, "\n"));
}

Using the following file as an example:

Hello to arabteam2000-forumThis was your first question which was too vague to interpret exactly what you meant
Next time please be more specific about your requirements

produces the following file:

Helloto
arabteam2000-forum
This
was
your
first
question
which
was
too
vague
to
interpret
exactly
what
you
meant
Next
time
please
be
more
specific
about
your
requirements
1

مواضيع مشابهة