| Title | Open | |||
|---|---|---|---|---|
| 574 | Read the First WordA text file contains words separated by spaces and newlines, for example: hello world Write a function string firstWord(const string& filename) that returns the first word of the file. | easy | Not started | Solve |
| 575 | Read One Integer from a FileA text file starts with a whole number, for example: 42 Write a function int readNumber(const string& filename) that returns the first integer stored in the file. | easy | Not started | Solve |
| 576 | Did the File Open?Write a function bool canOpen(const string& filename) that tries to open the file for reading and returns true if it opened successfully and false otherwise. | easy | Not started | Solve |
| 577 | Count LinesA text file contains one item per line, for example: red green blue Write a function int countLines(const string& filename) that returns how many lines the file has. | easy | Not started | Solve |
| 578 | Sum Numbers in a FileA text file contains whole numbers separated by spaces or newlines, for example: 10 20 30 Write a function int sumFile(const string& filename) that returns the sum of every number in the file. | easy | Not started | Solve |
| 579 | Read the First LineWrite a function string firstLine(const string& filename) that returns the entire first line of the file, spaces included. | easy | Not started | Solve |
| 580 | Print a FileWrite a function void printFile(const string& filename) that prints every line of the file to cout, in order, each followed by a newline. | easy | Not started | Solve |
| 581 | Count WordsA text file contains words separated by any mix of spaces and newlines, possibly with extra blank space, for example: the quick brown fox jumps Write a function int countWords(const string& filename) that returns how many words the file contains; a word is any run of non-whitespace characters. | easy | Not started | Solve |
| 582 | Read Mixed ValuesThe starter first writes the single line Alice 30 5.5 into person.txt (that part is done for you), then opens the file as ifstream in. | easy | Not started | Solve |
| 583 | Close and ReportThe starter writes hello into notes.txt, opens it as ifstream in, reads one word and prints Read: hello. | easy | Not started | Solve |
| 598 | Write One LineWrite a function void writeGreeting(const string& filename) that opens filename with an ofstream (the starter does this as out) and writes exactly one line: Hello, file! | easy | Not started | Solve |
| 599 | Write Numbers 1 to 5Write a function void writeNumbers(const string& filename) that opens filename with an ofstream and writes the integers 1, 2, 3, 4 and 5, one number per line (each followed by a newline). | easy | Not started | Solve |
| 600 | Write a Vector on One LineWrite a function void writeVector(const string& filename, const vector<int>& v) that opens filename with an ofstream and writes all the values of v on a single line, separated by single spaces, followed by one newline. | easy | Not started | Solve |
| 601 | Check Open Before WritingWrite a function bool saveText(const string& filename, const string& text) that opens filename with an ofstream (the starter does this as out). | easy | Not started | Solve |
| 602 | Append a LineWrite a function void appendLine(const string& filename, const string& line) that opens filename in append mode (ios::app) and writes line followed by a newline at the end of the file, keeping the existing contents. | easy | Not started | Solve |
| 603 | Write Then Read BackThe program opens the file words.txt with an ofstream called out, closes it, then reopens the same file with an ifstream and prints every line it finds. | easy | Not started | Solve |
| 604 | Save a PersonWrite a function void savePerson(const string& filename, const string& name, int age) that opens filename with an ofstream (the starter does this as out) and writes two lines: Name: followed by a space and the name, then Age: followed by a space and the age. | easy | Not started | Solve |
| 605 | Overwrite an Existing FileWrite a function void overwrite(const string& filename, const string& text) that replaces whatever the file currently contains with a single line: text followed by a newline. | easy | Not started | Solve |
| 606 | Close Before ReopeningThe program writes the line done to status.txt with an ofstream called out, then opens the same file with an ifstream and prints every line it contains. | easy | Not started | Solve |
| 607 | Write a Formatted PriceWrite a function void writePrice(const string& filename, double p) that opens filename with an ofstream (the starter does this as out) and writes one line: Price: followed by a space and p shown with exactly two digits after the decimal point, then a newline. | easy | Not started | Solve |
| 622 | Print to an ostream ParameterWrite a function void printHello(ostream& out) that writes the text Hello, stream! | easy | Not started | Solve |
| 623 | Sum to a StreamWrite a function void printSum(ostream& out, int a, int b) that writes the equation a + b = sum to out, followed by a newline. | easy | Not started | Solve |
| 624 | operator<< for a ColorA struct Rgb with three public ints r, g, b is given. | easy | Not started | Solve |
| 625 | setw Right AlignmentThe variable int value = 42; is declared for you. | easy | Not started | Solve |
| 626 | Zero Padding with setfillThe variable int id = 42; is declared for you. | easy | Not started | Solve |
| 627 | Two Decimal PlacesThe variable double pi = 3.14159; is declared for you. | easy | Not started | Solve |
| 628 | Left-Aligned ColumnThe variable string header = "Name"; is declared for you. | easy | Not started | Solve |
| 629 | Return the Stream for ChainingWrite a function ostream& printPair(ostream& out, int a, int b) that writes (a, b) — an opening parenthesis, the first number, a comma and a space, the second number, a closing parenthesis — to out with NO newline, and then returns out. | easy | Not started | Solve |
| 630 | cout Is an ostreamThe starter declares ostream& out = cout; and int total = 5;. | easy | Not started | Solve |
| 631 | Print a Vector to a StreamWrite a function void printVec(ostream& out, const vector<int>& v) that writes the elements of v inside square brackets, separated by a comma and a space, followed by a newline. | easy | Not started | Solve |
| 646 | fstream in Write ModeWrite a function void writeWithFstream(const string& filename, const string& text) that opens filename with an fstream in ios::out mode and writes text followed by a newline. | easy | Not started | Solve |
| 647 | fstream in Read ModeWrite a function string readWithFstream(const string& filename) that opens filename with an fstream in ios::in mode, reads the first line with getline, and returns it (without the newline). | easy | Not started | Solve |
| 648 | Append with fstreamWrite a function void appendFs(const string& filename, const string& line) that opens filename with an fstream in ios::out | ios::app mode and writes line followed by a newline. | easy | Not started | Solve |
| 649 | in-and-out Needs an Existing FileWrite a function bool openReadWrite(const string& filename) that opens filename with an fstream in ios::in | ios::out mode and returns whether the open succeeded (the result of is_open()). | easy | Not started | Solve |
| 650 | Write, Seek, ReadThe program below opens note.txt with an fstream in ios::in | ios::out | ios::trunc mode. | easy | Not started | Solve |
| 651 | tellg After ReadingThe program below writes the eleven characters hello world (no newline) into words.txt, then opens it for reading with an fstream. | easy | Not started | Solve |
| 652 | File Size with seekg/tellgWrite a function long fileSize(const string& filename) that opens filename with an fstream in ios::in | ios::binary mode (the open is already written for you), seeks to the end with seekg(0, ios::end), and returns tellg() cast to long. | easy | Not started | Solve |
| 653 | Reset a File with ios::truncWrite a function void resetFile(const string& filename) that opens filename with an fstream in ios::out | ios::trunc mode and writes the single line reset (followed by a newline) to it. | easy | Not started | Solve |
| 654 | Count Reads Until FailureThe program below writes 5 10 15 into numbers.txt and opens it for reading with an fstream. | easy | Not started | Solve |
| 655 | Reuse One fstream ObjectThe program below opens data.txt for writing with an fstream, writes the number 42, and later reads a number back from the same stream object. | easy | Not started | Solve |
| 584 | Largest Number in a FileA text file contains one or more integers separated by spaces or newlines, for example: 12 91 5 44 Write a function int maxInFile(const string& filename) that opens the file, reads every integer with >> and returns the largest one. | medium | Not started | Solve |
| 585 | Number Each LineWrite a function void printNumbered(const string& filename) that prints every line of the file preceded by its 1-based line number, a colon and one space. | medium | Not started | Solve |
| 586 | Line Containing a WordWrite a function int lineOf(const string& filename, const string& word) that returns the 1-based number of the first line of the file that contains word anywhere inside it, or -1 if no line contains it. | medium | Not started | Solve |
| 587 | Average with Missing-File BranchWrite a function void printAverage(const string& filename). | medium | Not started | Solve |
| 588 | Parse Name,Score LinesA file holds one record per line in the form name,score with no spaces around the comma: Bob,90 Amy,85 Write a function void printScores(const string& filename) that prints one line per record in the form <name> scored <score>, in file order, each ending with a newline (see Expected Output). | medium | Not started | Solve |
| 589 | Longest LineWrite a function string longestLine(const string& filename) that returns the line of the file with the most characters. | medium | Not started | Solve |
| 590 | Count a Character with getWrite a function int countChar(const string& filename, char c) that returns how many times the character c appears in the file. | medium | Not started | Solve |
| 591 | Read a Config ValueA configuration file holds one key=value pair per line with no spaces around the =: host=localhost port=8080 debug=true Write a function string getValue(const string& filename, const string& key) that returns the value whose key matches key exactly (the whole text before the =), or the string not found if no line has that key. | medium | Not started | Solve |
| 592 | Skip the Header LineThe first line of the file is a text header that must be skipped; every line after it holds integers separated by spaces or newlines: scores 20 25 30 Write a function int sumAfterHeader(const string& filename) that returns the sum of all the numbers after the header. | medium | Not started | Solve |
| 593 | Lines Containing TextWrite a function vector<string> linesContaining(const string& filename, const string& sub) that returns, in file order, every line that contains sub as a substring. | medium | Not started | Solve |
| 608 | Squares TableWrite a function void writeSquares(const string& filename, int n) that opens filename with an ofstream and writes one line for every integer k from 1 to n (n is always at least 1). | medium | Not started | Solve |
| 609 | Write Only EvensWrite a function int writeEvens(const string& filename, const vector<int>& v) that opens filename with an ofstream and writes only the even values of v, in their original order, on a single line separated by single spaces, with no space before the first value, followed by one newline. | medium | Not started | Solve |
| 610 | Copy a FileWrite a function bool copyFile(const string& src, const string& dst) that copies a text file line by line. | medium | Not started | Solve |
| 611 | Event LogWrite a function void logEvent(const string& filename, const string& msg) that opens the log file in append mode and adds one line at the end without erasing the lines already there: LOG: followed by a space and msg, then a newline. | medium | Not started | Solve |
| 612 | Save stdin UppercasedRead every line from standard input until the input ends, convert each line to uppercase, and write the uppercased lines to the file input_copy.txt (create or truncate it; one line per input line, each followed by a newline). | medium | Not started | Solve |
| 613 | Aligned Table to FileWrite a function void writeTable(const string& filename, const vector<pair<string, int>>& rows) that opens filename with an ofstream and writes one line per row: the name left-aligned in a field 8 characters wide (left, setw(8)), immediately followed by the quantity right-aligned in a field 4 characters wide (right, setw(4)), then a newline. | medium | Not started | Solve |
| 614 | Write CSVWrite a function void writeCsv(const string& filename, const vector<string>& names, const vector<int>& scores) that opens filename with an ofstream and writes one line per index i: names[i], a comma (no spaces around it), scores[i], then a newline. | medium | Not started | Solve |
| 615 | Receipt with TotalWrite a function void writeReceipt(const string& filename, const vector<double>& prices) that opens filename with an ofstream and writes one line per price, numbered from 1, in the form Item 1: 3.50. | medium | Not started | Solve |
| 616 | Truncate or AppendWrite a function void save(const string& filename, const string& text, bool append) that writes text followed by a newline to filename. | medium | Not started | Solve |
| 617 | Multiplication Grid to a FileWrite a function void writeGrid(const string& filename, int n) that opens filename with an ofstream and writes an n by n multiplication table. | medium | Not started | Solve |
| 632 | operator<< for MoneyA class Money that stores a whole number of cents is given, together with a friend declaration for operator<<. | medium | Not started | Solve |
| 633 | Table Row HelperWrite a function void printRow(ostream& out, const string& name, int qty, double price) that writes one table row to out and ends it with a newline. | medium | Not started | Solve |
| 634 | Polymorphic print(ostream&)An abstract base class Shape is given in the starter with the pure virtual method virtual void print(ostream& out) const = 0;. | medium | Not started | Solve |
| 635 | Percent FormatterWrite a function void printPercent(ostream& out, double ratio) that takes a ratio between 0 and 1, multiplies it by 100, and writes the result to out with exactly one decimal place, immediately followed by a % sign and a newline. | medium | Not started | Solve |
| 636 | operator<< for PlaylistA class Playlist holding a vector<string> of song names is given, together with a friend declaration for operator<<. | medium | Not started | Solve |
| 637 | Receipt to Any StreamWrite a function void receipt(ostream& out, const vector<pair<string, double>>& items) that writes one line per item — the item name, a single space, and the price with exactly 2 decimal places — and then a final line Total: followed by the sum of all prices, also with 2 decimals. | medium | Not started | Solve |
| 638 | Chainable BannerWrite a function ostream& banner(ostream& out, const string& title) that writes three equals signs, a space, the title, a space, and three equals signs (=== title ===) to out with NO newline, and returns out. | medium | Not started | Solve |
| 639 | Hex and DecimalWrite a function void printHexDec(ostream& out, int n) that writes n in decimal, then a space, an equals sign, a space and 0x, then n again in lowercase hexadecimal (no padding), then a newline — for 255 the line is 255 = 0xff, for 0 it is 0 = 0x0. | medium | Not started | Solve |
| 640 | boolalpha FlagsWrite a function void printFlags(ostream& out, bool a, bool b) that writes a= followed by the first flag, a space, b= followed by the second flag, and a newline — with the flags printed as the words true / false. | medium | Not started | Solve |
| 641 | Matrix to StreamWrite a function void printMatrix(ostream& out, const vector<vector<int>>& m) that writes each row of the matrix on its own line, with every value right-aligned in a field 4 characters wide (padded with spaces on the left) and nothing else between values. | medium | Not started | Solve |
| 656 | Write Then Read in One ObjectWrite a function int writeAndSum(const string& filename, const vector<int>& v) that uses ONE fstream object for both directions: 1. | medium | Not started | Solve |
| 657 | Append Then Count LinesWrite a function int appendAndCount(const string& filename, const string& line) that: 1. | medium | Not started | Solve |
| 658 | Persistent CounterWrite a function int incrementCounter(const string& filename) that: 1. | medium | Not started | Solve |
| 659 | Replace a WordWrite a function int replaceWord(const string& filename, const string& from, const string& to) that replaces every whole word equal to from with to inside a text file and returns how many words were replaced. | medium | Not started | Solve |
| 660 | Read the Nth Fixed RecordWrite a function string nthRecord(const string& filename, int n) that opens filename with an fstream in ios::in | ios::binary mode, seeks the read position to byte n 4, reads that one record with getline, and returns the three letters (without the newline). | medium | Not started | Solve |
| 661 | Numbered AppendWrite a function void appendNumbered(const string& filename, const string& msg) that appends a numbered line: the number is one more than the number of lines the file already contains, so the first message becomes 1. | medium | Not started | Solve |
| 662 | Capitalize the First CharacterWrite a function void capitalizeFirst(const string& filename) that opens filename with an fstream in ios::in | ios::out mode, reads its first character with get, moves the write position back to the start with seekp(0), and writes the uppercase version of that character (use toupper from <cctype>) over it with put. | medium | Not started | Solve |
| 663 | Notes from stdinWrite a program that reads lines from standard input until the input ends, stores them in a file, then reads the file back through the same fstream object and prints the numbered notes. | medium | Not started | Solve |
| 664 | Strip Blank LinesWrite a function int stripBlankLines(const string& filename) that removes every blank line from a text file and returns how many lines were removed. | medium | Not started | Solve |
| 665 | Reverse Lines in PlaceWrite a function void reverseLines(const string& filename) that reverses the order of the lines in a text file: the last line becomes the first, and so on. | medium | Not started | Solve |
| 724 | Ticket Line That Leaves the Stream UntouchedTicket is written for you, with a friend declaration for operator<<. | medium | Not started | Solve |
| 725 | Receipts Numbered by a Static CounterReceipt is written for you with a friend declaration. | medium | Not started | Solve |
| 594 | Grade Book ReportWrite a function void gradeReport(const string& filename). | hard | Not started | Solve |
| 595 | Transpose a Matrix FileThe first line of the file holds two integers R C: the number of rows and the number of columns. | hard | Not started | Solve |
| 596 | Log Reader ClassCreate a class LogReader that loads a log file in its constructor. | hard | Not started | Solve |
| 597 | First Differing LineWrite a function int firstDifference(const string& a, const string& b) that compares two text files line by line and returns the 1-based number of the first line where they differ, or 0 if the files are identical. | hard | Not started | Solve |
| 618 | Rotating LoggerCreate a class Logger that writes log lines to a file but never lets the file grow beyond a limit. | hard | Not started | Solve |
| 619 | Split by ParityWrite a function void splitByParity(const string& src, const string& evens, const string& odds) that reads all the whitespace-separated integers from the file src and writes every even integer to the file evens and every odd integer to the file odds, in the order they were read. | hard | Not started | Solve |
| 620 | High Scores Save and LoadCreate a class HighScores that keeps a list of (name, score) entries. | hard | Not started | Solve |
| 621 | Word Counts to FileWrite a function void writeWordCounts(const string& src, const string& dst) that reads every whitespace-separated word from the file src, counts how many times each word appears, and writes the result to the file dst (created or truncated): one line per distinct word, in alphabetical order, as the word, a space, its count, then a newline. | hard | Not started | Solve |
| 642 | Inventory Report operator<<Build a class Inventory: 1. | hard | Not started | Solve |
| 643 | Polymorphic Employee ReportThe starter gives an abstract base class Employee: a protected name, the constructor Employee(const string& name), and virtual void describe(ostream& out) const = 0;. | hard | Not started | Solve |
| 644 | Indented Tree PrinterBuild a class Node representing one node of a tree: 1. | hard | Not started | Solve |
| 645 | Restore Stream StateWrite a function void printMoney(ostream& out, double v) that writes a dollar sign followed by v with exactly two decimals and a newline ($1234.50 for 1234.5), then leaves out in exactly the state it found it. | hard | Not started | Solve |
| 666 | File-Backed Key-Value StoreBuild a class KVStore that keeps string keys and values in a text file: one entry per line as the key, a space, the value (e.g. | hard | Not started | Solve |
| 667 | Fixed-Width Record EditorBuild a class RecordFile that stores names in a binary file as fixed-width records of exactly 8 bytes, no separators. | hard | Not started | Solve |
| 668 | Bank Ledger FileBuild a class Ledger that records bank transactions in a text file and recomputes the balance from that file every time it is asked — nothing is cached. | hard | Not started | Solve |
| 669 | Merge Two Files UniquelyWrite a function int mergeUnique(const string& a, const string& b, const string& out) that reads two text files and writes a third one containing every distinct line from either input, sorted in ascending (dictionary) order, one per line, each followed by a newline. | hard | Not started | Solve |