Question about getline with fstream

  • Thread starter Thread starter yungman
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around the use of the getline function with fstream in C++, specifically addressing issues encountered when reading from files into strings and character arrays. Participants explore the behavior of different getline methods and file pointer manipulations, as well as the confusion arising from compile errors and program execution.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant describes a program that uses getline to read from a file into a string and notes that it compiles but produces errors when using a different getline method with an array.
  • Another participant suggests reviewing the specifications for the getline methods to clarify the observations made.
  • A participant expresses frustration over not understanding the API specifications and the concepts of classes and templates, indicating a lack of prior study in these areas.
  • Concerns are raised about the behavior of file pointer movements when using seekg and get methods, with one participant detailing their confusion over expected versus actual cursor positions in the file.
  • Clarifications are provided regarding how the position-in-file pointer is affected by read and write operations, explaining that it advances after such operations.
  • Another participant points out that getline() and fstream::getline() are different functions, which may explain the inconsistencies experienced by the original poster.
  • Discussions include the implications of using seekg with different parameters and the resulting behavior of the file pointer, with suggestions for using tellg and peek to understand cursor positions better.

Areas of Agreement / Disagreement

Participants express varying levels of understanding regarding the getline function and file pointer behavior, with some clarifying points for others while disagreements about expected outcomes remain unresolved. The discussion does not reach a consensus on the best approach to address the original poster's issues.

Contextual Notes

Participants note limitations in understanding due to a lack of familiarity with certain programming concepts, such as classes and templates, which may affect their ability to fully grasp the issues discussed.

  • #61
phinds said:
You set a TIME goal. Why not set a LEARNING goal instead?

A time goal without a learning goal can be met just by waiting.
 
  • Like
Likes   Reactions: sysprog
Technology news on Phys.org
  • #62
Vanadium 50 said:
A time goal without a learning goal can be met just by waiting.
Yeah, but he's setting very brief time goals.
 
  • #63
All the faster. :wink:
 
  • Haha
Likes   Reactions: phinds
  • #64
There's the old line "I took a speed-reading class and was able to read War & Peace in twenty minutes. It's about Russia."
 
  • Haha
Likes   Reactions: sysprog
  • #65
Vanadium 50 said:
There's the old line "I took a speed-reading class and was able to read War & Peace in twenty minutes. It's about Russia."
Reminds me of:
1601298941329.png
 
  • Haha
Likes   Reactions: sysprog
  • #66
The question about how file input works has been beaten to death, so this seems like a good place to end the thread.
 

Similar threads

  • · Replies 32 ·
2
Replies
32
Views
4K
Replies
6
Views
2K
  • · Replies 70 ·
3
Replies
70
Views
5K
Replies
20
Views
2K
  • · Replies 118 ·
4
Replies
118
Views
10K
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 33 ·
2
Replies
33
Views
3K
Replies
10
Views
2K