| | |
sort string in file txt
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2006
Posts: 17
Reputation:
Solved Threads: 0
can anybody give me an idea how to sort string in alphabetical order in file.text after user input string and in the file already had a list of string?
which is the best,let user input the all string first then sorting it or sorting if after user input the string?
this is the content of the file
which is the best,let user input the all string first then sorting it or sorting if after user input the string?
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <fstream.h> void main() { fstream kamus("Adkjektif.txt",ios::in | ios::out | ios::app); const size = 30; char kata2[size]; cout<<"input string (end for stop)"<<endl; for(;;) { cin.getline(kata2,size); if (strcmpi(kata2,"end")==0) break; else kamus<<kata2<<endl; } kamus.close(); }
this is the content of the file
C++ Syntax (Toggle Plain Text)
small tall big
there are methods of sorting text files, but they are generally pretty complicated. If the file is small enough, just read all the strings into an in-memory array, sort the array, then rewrite them back to the file. If you are writing c++ program that is pretty easy -- read the strings into a std::vector<std::string> array, then use std::sort() to sort it.
Use a pretty recent compiler such as Dev-C++. The code you posted uses iostream.h which has been obsolete for several years, so I suspect you are using a pretty ancient compiler such as Turbo C++.
Use a pretty recent compiler such as Dev-C++. The code you posted uses iostream.h which has been obsolete for several years, so I suspect you are using a pretty ancient compiler such as Turbo C++.
![]() |
Similar Threads
- dat file txt file help???? (C)
- How to search for a string in a file (C#)
- Selection Sort and String (C++)
- find strings in file.txt (C++)
- assigning a string from a file to a variable (C++)
- Bubble sort & File output jibrish errors??? (C)
Other Threads in the C++ Forum
- Previous Thread: C++ program error
- Next Thread: broken code
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






