• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:14
CEST 15:14
KST 22:14
  • 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
Team Liquid Map Contest #22 - The Finalists12[ASL21] Ro16 Preview Pt1: Fresh Flow9[ASL21] Ro24 Preview Pt2: News Flash10[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy21
Community News
2026 GSL Season 1 Qualifiers11Maestros of the Game 2 announced32026 GSL Tour plans announced10Weekly Cups (April 6-12): herO doubles, "Villains" prevail0MaNa leaves Team Liquid20
StarCraft 2
General
MaNa leaves Team Liquid Oliveira Would Have Returned If EWC Continued Team Liquid Map Contest #22 - The Finalists 2026 GSL Tour plans announced Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool
Tourneys
2026 GSL Season 1 Qualifiers Sparkling Tuna Cup - Weekly Open Tournament Master Swan Open (Global Bronze-Master 2) SEL Doubles (SC Evo Bimonthly) $5,000 WardiTV TLMC tournament - Presented by Monster Energy
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 521 Memorable Boss The PondCast: SC2 News & Results Mutation # 520 Moving Fees Mutation # 519 Inner Power
Brood War
General
Pros React To: Tulbo in Ro.16 Group A mca64Launcher - New Version with StarCraft: Remast BGH Auto Balance -> http://bghmmr.eu/ Data needed BW General Discussion
Tourneys
[ASL21] Ro16 Group B Korean KCM Race Survival 2026 Season 2 [Megathread] Daily Proleagues [ASL21] Ro16 Group A
Strategy
What's the deal with APM & what's its true value Any training maps people recommend? Fighting Spirit mining rates Muta micro map competition
Other Games
General Games
General RTS Discussion Thread Battle Aces/David Kim RTS Megathread Nintendo Switch Thread Stormgate/Frost Giant Megathread Starcraft Tabletop Miniature Game
Dota 2
The Story of Wings Gaming Official 'what is Dota anymore' discussion
League of Legends
G2 just beat GenG in First stand
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 Five o'clock TL Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine YouTube Thread Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books [Manga] One Piece Movie Discussion!
Sports
McBoner: A hockey love story 2024 - 2026 Football Thread Formula 1 Discussion Cricket [SPORT]
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Reappraising The Situation T…
TrAiDoS
lurker extra damage testi…
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1763 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
WardiTV Map Contest Tou…
11:00
Group A
WardiTV859
TKL 185
IndyStarCraft 183
Rex123
3DClanTV 57
EnkiAlexander 31
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
TKL 185
IndyStarCraft 183
Hui .148
Rex 123
BRAT_OK 88
StarCraft: Brood War
Britney 44513
Calm 6546
Horang2 1805
Bisu 1748
Jaedong 1139
firebathero 905
Soma 354
Mini 342
Larva 297
ggaemo 231
[ Show more ]
actioN 215
Light 182
Zeus 167
Leta 152
Last 150
Hyuk 147
Sharp 111
Soulkey 106
Pusan 104
hero 73
ToSsGirL 71
Hyun 68
Rush 66
Sea.KH 53
Aegong 45
Shinee 38
Sexy 37
Backho 35
Hm[arnc] 27
JYJ 24
yabsab 20
soO 17
sorry 17
Nal_rA 17
zelot 16
IntoTheRainbow 15
Sacsri 13
Bale 12
GoRush 12
Terrorterran 12
NaDa 11
SilentControl 8
Icarus 6
Dota 2
Gorgc3653
qojqva1013
Counter-Strike
shoxiejesuss852
x6flipin325
Super Smash Bros
Mew2King98
Heroes of the Storm
XaKoH 36
Other Games
singsing1733
B2W.Neo1040
Liquid`RaSZi976
DeMusliM340
crisheroes321
Lowko279
mouzStarbuck72
Sick61
QueenE40
Trikslyr16
KnowMe5
Organizations
StarCraft: Brood War
UltimateBattle 919
Counter-Strike
PGL138
StarCraft: Brood War
lovetv 11
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Kozan
• Migwel
• AfreecaTV YouTube
• intothetv
• sooper7s
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• FirePhoenix7
• Michael_bg 3
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• Noizen30
League of Legends
• Jankos1502
• TFBlade1421
Upcoming Events
CranKy Ducklings
10h 46m
Escore
20h 46m
WardiTV Map Contest Tou…
21h 46m
OSC
1d 1h
Korean StarCraft League
1d 13h
CranKy Ducklings
1d 20h
WardiTV Map Contest Tou…
1d 21h
IPSL
2 days
WolFix vs nOmaD
dxtr13 vs Razz
BSL
2 days
UltrA vs KwarK
Gosudark vs cavapoo
dxtr13 vs HBO
Doodle vs Razz
Sparkling Tuna Cup
2 days
[ Show More ]
WardiTV Map Contest Tou…
2 days
Ladder Legends
3 days
BSL
3 days
StRyKeR vs rasowy
Artosis vs Aether
JDConan vs OyAji
Hawk vs izu
IPSL
3 days
JDConan vs TBD
Aegong vs rasowy
Replay Cast
3 days
Replay Cast
3 days
Wardi Open
3 days
Afreeca Starleague
3 days
Bisu vs Ample
Jaedong vs Flash
Monday Night Weeklies
4 days
RSL Revival
4 days
Afreeca Starleague
4 days
Barracks vs Leta
Royal vs Light
WardiTV Map Contest Tou…
4 days
RSL Revival
5 days
Replay Cast
6 days
The PondCast
6 days
WardiTV Map Contest Tou…
6 days
Liquipedia Results

Completed

Proleague 2026-04-15
RSL Revival: Season 4
NationLESS Cup

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
StarCraft2 Community Team League 2026 Spring
WardiTV TLMC #16
Nations Cup 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026

Upcoming

Escore Tournament S2: W3
Escore Tournament S2: W4
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
2026 GSL S2
RSL Revival: Season 5
2026 GSL S1
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
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.