Re: ifstream code to read a paragraph

From: Josh Sebastian (curien_at_cox.net)
Date: 10/31/03


Date: Thu, 30 Oct 2003 20:38:59 -0500

On Thu, 30 Oct 2003 22:52:52 +0000, CJ wrote:

> snip of code below - trying to read in a file with a paragraph in it.
> The file is being read in but only the first word of the paragraph displays
> The CHAR probably has to be changed but to what can't find a reference in my
> book
> I'm just practicing on how to get my program to read from a text file
> Any help appreciated - I'm just learning
>
> int main()
> {
> ifstream inFile;
> char message [81];
>
> inFile.open("message.txt");
> inFile >> message;
>
> cout << message <<endl;

That's because you only asked it to read one word. Remember that
operator>> will stop reading when it sees whitespace. Also note that the
first word could be more than 80 characters, causing your program to have
a buffer overrun. Much safer is to use the std::string class.

How do you define a paragraph? Is it defined by two newlines in a row
(roughly how I am splitting my paragraphs in this post)? Does it end (and
the next one start) when you see a newline followed by a tab? Or maybe
something else? Think about these things (design decisions), try again,
and if you're still having trouble, ask for more help.

Josh



Relevant Pages

  • Re: wants to capitalize the first letter in the first word of ever
    ... The "capitalize first word of sentence" you mention in your first ... letting lines wrap naturally. ... the start of a new paragraph and I always do capitalize that. ... And if you don't want to see the green squiggles, ...
    (microsoft.public.word.docmanagement)
  • Re: wants to capitalize the first letter in the first word of ever
    ... Microsoft MVP (Word) ... The "capitalize first word of sentence" you mention in your first ... letting lines wrap naturally. ... the start of a new paragraph and I always do capitalize that. ...
    (microsoft.public.word.docmanagement)
  • Re: Size of an em
    ... a space used before the first word of a new paragraph ... ... three spaces at the end of a sentence unless it ended a paragraph, and two spaces after a colon, semicolon, exclamation mark and question mark. ...
    (comp.infosystems.www.authoring.stylesheets)
  • Re: wants to capitalize the first letter in the first word of ever
    ... For those pasted docs with lines that end in line or paragraph breaks, ... But is there a way to stop Word from wanting to capitalize the shorter ... letting lines wrap naturally. ... >> Word wouldn't want to capitalize the first word of every line if it>> were ...
    (microsoft.public.word.docmanagement)
  • Re: Styles dont apply in Word 2003
    ... the notorious "Char Char" bug. ... you apply a paragraph style to a selection that is not a whole ... Create a new temporary style. ... Sub StylesDeleteParaAndChar() ...
    (microsoft.public.word.formatting.longdocs)