• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 22:07
CET 04:07
KST 12:07
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
ByuL: The Forgotten Master of ZvT28Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8
Community News
Weekly Cups (Feb 16-22): MaxPax doubles0Weekly Cups (Feb 9-15): herO doubles up2ACS replaced by "ASL Season Open" - Starts 21/0258LiuLi Cup: 2025 Grand Finals (Feb 10-16)46Weekly Cups (Feb 2-8): Classic, Solar, MaxPax win2
StarCraft 2
General
Terran AddOns placement How do you think the 5.0.15 balance patch (Oct 2025) for StarCraft II has affected the game? Nexon's StarCraft game could be FPS, led by UMS maker ByuL: The Forgotten Master of ZvT Oliveira Would Have Returned If EWC Continued
Tourneys
PIG STY FESTIVAL 7.0! (19 Feb - 1 Mar) SEL Doubles (SC Evo Bimonthly) WardiTV Team League Season 10 RSL Season 4 announced for March-April The Dave Testa Open #11
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026] Map Editor closed ?
External Content
Mutation # 514 Ulnar New Year The PondCast: SC2 News & Results Mutation # 513 Attrition Warfare Mutation # 512 Overclocked
Brood War
General
TvZ is the most complete match up BGH Auto Balance -> http://bghmmr.eu/ Soma Explains: JD's Unrelenting Aggro vs FlaSh ACS replaced by "ASL Season Open" - Starts 21/02 BW General Discussion
Tourneys
[Megathread] Daily Proleagues [LIVE] [S:21] ASL Season Open Day 1 ASL Season 21 Qualifiers March 7-8 Small VOD Thread 2.0
Strategy
Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates Simple Questions, Simple Answers Zealot bombing is no longer popular?
Other Games
General Games
Nintendo Switch Thread Battle Aces/David Kim RTS Megathread Path of Exile Beyond All Reason New broswer game : STG-World
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine UK Politics Mega-thread YouTube Thread Mexico's Drug War
Fan Clubs
The IdrA Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece [Req][Books] Good Fantasy/SciFi books Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TL MMA Pick'em Pool 2013
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
YOUTUBE VIDEO
XenOsky
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Inside the Communication of …
TrAiDoS
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2253 users

Little C++ Question

Blogs > EsX_Raptor
Post a Reply
EsX_Raptor
Profile Blog Joined February 2008
United States2802 Posts
November 12 2008 18:00 GMT
#1
Assume I have a file with this content:

a b c d
e f g h i
j k l

and I have a char variable a:

char a;

Now suppose I read each letter and do something with it, such as converting it to a number. The desired output in a new file should be:

1 2 3 4
5 6 7 8 9
10 11 12

Don't pay attention to the numbers, but rather the format of the output (3 lines).

My problem is: I don't know how to read the newline character correctly. I've already tried

File >> a;
if (a == '\n')
Out << '\n';

That would create a new line in the output file. But for some reason it just doesnt work and the output is the following:

1 2 3 4 5 6 7 8 9 10 11 12

No formatting. Anyone has suggestions on how to create that newline?

*
EsX_Raptor
Profile Blog Joined February 2008
United States2802 Posts
November 12 2008 18:09 GMT
#2
Apparently the newline character '\n' cannot be read by the char variable a and thus the "if" isn't executed. -.-
dyodyo
Profile Blog Joined December 2005
Philippines578 Posts
Last Edited: 2008-11-12 18:11:43
November 12 2008 18:10 GMT
#3
edit
+ Show Spoiler +

Try this and see if it works...
Try viewing the file in a hex editor to see if the newline character is correctly inserted in the file (ascii code 10). You can also try viewing the file in wordpad. Note that windows uses the \r\n combination as line endings. So if you just insert \n and open the file in notepad, it wont have multiple lines (but you would see a block character where the \n characters are located.

nice to see you figured it out
TeamLiquid CJ Entusman #26
freelander
Profile Blog Joined December 2004
Hungary4707 Posts
November 12 2008 18:15 GMT
#4
>> operator doesn't read whitespace characters such space, /n , tab I think.
You should use the std function getline(i instream, string s), it reads a whole a line from an instream and writes to string s.
And all is illuminated.
EsX_Raptor
Profile Blog Joined February 2008
United States2802 Posts
November 12 2008 18:21 GMT
#5
But my program is designed to read each input in the file one at a time and perform some operation on them.

And as you said, >> operator doesn't read whitespaces nor '\n' symbol.

if I add, say a letter 'x' at the end of each line and go:

if (a == 'x')
Out << '\n';

it works fine -.-
freelander
Profile Blog Joined December 2004
Hungary4707 Posts
Last Edited: 2008-11-12 18:31:53
November 12 2008 18:29 GMT
#6
On November 13 2008 03:21 EsX_Raptor wrote:
But my program is designed to read each input in the file one at a time and perform some operation on them.

And as you said, >> operator doesn't read whitespaces nor '\n' symbol.

if I add, say a letter 'x' at the end of each line and go:

if (a == 'x')
Out << '\n';

it works fine -.-


ok.. but adding an additional x sounds silly because if you have to work with files like this(for example ini files) you should use the getline.
if you read a line into a string var, you can see what was the last character in that line.
If you know this, you can add a /n after converting the said letter to number.
And all is illuminated.
MasterZilla
Profile Blog Joined November 2003
Sweden234 Posts
November 12 2008 18:30 GMT
#7
You can open the stream with the 'noskipws' flag, which allows you to read whitespace.

As for the line breaking, use Out << endl; in stead.
For Aiur! - If you reach for the stars and miss, you still might end up walking among the clouds.
freelander
Profile Blog Joined December 2004
Hungary4707 Posts
November 12 2008 18:34 GMT
#8
On November 13 2008 03:30 MasterZilla wrote:
You can open the stream with the 'noskipws' flag, which allows you to read whitespace.

As for the line breaking, use Out << endl; in stead.


hey, how should this be done?

ifstream f("fname.txt");

where to put this flag?
And all is illuminated.
Moaf_
Profile Joined September 2006
Austria76 Posts
November 12 2008 18:41 GMT
#9
Google is your friend

Link
No Risk - No Fun
freelander
Profile Blog Joined December 2004
Hungary4707 Posts
November 12 2008 18:45 GMT
#10
On November 13 2008 03:41 Moaf_ wrote:
Google is your friend

Link


thanks (and wikipedia is your girlfriend, i know i know)
And all is illuminated.
Moaf_
Profile Joined September 2006
Austria76 Posts
November 12 2008 19:08 GMT
#11
nah, wikipedia is actually a whore
No Risk - No Fun
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
LiuLi Cup Grand Finals Group B
CranKy Ducklings182
LiquipediaDiscussion
AI Arena Tournament
20:00
RO8
DaveTesta Events
18:15
The Dave Testa Open #11
davetesta71
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 248
NeuroSwarm 136
Ketroc 55
StarCraft: Brood War
GuemChi 2571
ggaemo 233
NaDa 84
Shine 57
Dota 2
LuMiX2
Super Smash Bros
hungrybox1081
Heroes of the Storm
Khaldor163
Other Games
summit1g8103
JimRising 499
ViBE107
Organizations
Other Games
gamesdonequick780
Counter-Strike
PGL218
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Hupsaiya 428
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• HerbMon 36
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Doublelift7088
• Rush448
Upcoming Events
PiG Sty Festival
5h 53m
Clem vs Serral
Maru vs ShoWTimE
Sparkling Tuna Cup
6h 53m
uThermal 2v2 Circuit
11h 53m
Replay Cast
1d 5h
Wardi Open
1d 8h
Monday Night Weeklies
1d 13h
Replay Cast
1d 20h
Replay Cast
3 days
Replay Cast
3 days
The PondCast
4 days
[ Show More ]
KCM Race Survival
4 days
Replay Cast
4 days
Replay Cast
5 days
CranKy Ducklings
6 days
Replay Cast
6 days
Liquipedia Results

Completed

[S:21] ASL SEASON OPEN 2nd Round
LiuLi Cup: 2025 Grand Finals
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Acropolis #4 - TS5
Jeongseon Sooper Cup
Spring Cup 2026
WardiTV Winter 2026
PiG Sty Festival 7.0
Nations Cup 2026
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025

Upcoming

ASL Season 21: Qualifier #1
ASL Season 21: Qualifier #2
ASL Season 21
Acropolis #4 - TS6
Acropolis #4
IPSL Spring 2026
CSLAN 4
HSC XXIX
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
RSL Revival: Season 4
NationLESS Cup
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
FISSURE Playground #3
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.