• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 10:09
CET 16:09
KST 00:09
  • 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
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
RSL Offline Finals Info - Dec 13 and 14! Sparkling Tuna Cup - Weekly Open Tournament StarCraft Evolution League (SC Evo Biweekly) Sea Duckling Open (Global, Bronze-Diamond) $5,000+ WardiTV 2025 Championship
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
Foreign Brood War BW General Discussion MBCGame Torrents [ASL20] Ask the mapmakers — Drop your questions Which season is the best in ASL?
Tourneys
Small VOD Thread 2.0 [Megathread] Daily Proleagues [BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread ZeroSpace Megathread The Perfect Game
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
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
Formula 1 Discussion 2024 - 2026 Football Thread NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
I decided to write a webnov…
DjKniteX
Physical Exertion During Gam…
TrAiDoS
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1706 users

C++ noob question - Page 2

Blogs > eMbrace
Post a Reply
Prev 1 2 All
vAltyR
Profile Blog Joined July 2008
United States581 Posts
October 17 2009 03:19 GMT
#21
cin >> ch;


You're reading in from a file, not the command prompt. You need to use file IO commands instead of cin.

while ( cin )
{...}


That's not going to work. You need some kind of boolean logic statement there. Typically what I've done in my C++ class is we have a sentinel character and then loop until the sentinel character. I'm surprised that even compiled... Hmmm...

Yeah, didn't compile for me. Did it compile for you?
내 호버크라프트는 장어로 가득 차 있어요
eMbrace
Profile Blog Joined January 2009
United States1300 Posts
October 17 2009 03:22 GMT
#22
On October 17 2009 12:19 vAltyR wrote:
Show nested quote +
cin >> ch;


You're reading in from a file, not the command prompt. You need to use file IO commands instead of cin.

Show nested quote +
while ( cin )
{...}


That's not going to work. You need some kind of boolean logic statement there. Typically what I've done in my C++ class is we have a sentinel character and then loop until the sentinel character. I'm surprised that even compiled... Hmmm...

Yeah, didn't compile for me. Did it compile for you?


my code compiled fine and by adding the cout statement that people recommended fixed my issue -- all the decoding showed up in a new file (using -- pgm 6 < input.txt > new.txt) and it's all correctly decoded.



Ironson
Profile Joined February 2008
20 Posts
October 17 2009 03:25 GMT
#23
On October 17 2009 12:19 vAltyR wrote:
Show nested quote +
cin >> ch;


You're reading in from a file, not the command prompt. You need to use file IO commands instead of cin.

Show nested quote +
while ( cin )
{...}


That's not going to work. You need some kind of boolean logic statement there. Typically what I've done in my C++ class is we have a sentinel character and then loop until the sentinel character. I'm surprised that even compiled... Hmmm...

Yeah, didn't compile for me. Did it compile for you?


The '<' in the shell is the pipes the file's contents into the program through standard input - perfectly acceptable and extremely common when programming in Unix environments. The end of the file is delimited by the EOF character, and cin's implicit conversion to bool will return false when it is reached.
vAltyR
Profile Blog Joined July 2008
United States581 Posts
October 17 2009 03:26 GMT
#24
On October 17 2009 12:22 eMbrace wrote:
Show nested quote +
On October 17 2009 12:19 vAltyR wrote:
cin >> ch;


You're reading in from a file, not the command prompt. You need to use file IO commands instead of cin.

while ( cin )
{...}


That's not going to work. You need some kind of boolean logic statement there. Typically what I've done in my C++ class is we have a sentinel character and then loop until the sentinel character. I'm surprised that even compiled... Hmmm...

Yeah, didn't compile for me. Did it compile for you?


my code compiled fine and by adding the cout statement that people recommended fixed my issue -- all the decoding showed up in a new file (using -- pgm 6 < input.txt > new.txt) and it's all correctly decoded.

Odd. *shrugs* Different compilers are different, I guess. If it works, no sense worrying about it.
내 호버크라프트는 장어로 가득 차 있어요
AcrossFiveJulys
Profile Blog Joined September 2005
United States3612 Posts
October 17 2009 03:43 GMT
#25
On October 17 2009 12:05 keV. wrote:
Show nested quote +
On October 17 2009 12:03 AcrossFiveJulys wrote:
On October 17 2009 12:00 keV. wrote:
Wait a minute something isn't right here.


I'm pretty sure you can't read a txt file with cin, while expecting a char.


Yes you can. Since he's using the "<" operator when running the program, it changes the stdin stream (which is what cin uses) to refer to the file instead of user input.


I don't think reading from a file without a file handle is a good idea.

its sad how long its been since I've worked with simple I/O input...


I don't know what you mean by "isn't a good idea", but it's obvious that you don't know how I/O redirection works.

Here's a basic run down: a file handle is just a file descriptor that allows you read from the file. Similarly, stdin is a file descriptor that allows you to read from user input entered into the terminal. When you use the "<" and ">" operators when running a program, the shell is just changing the file descriptors that the program has when it starts.

So when you use "< file.txt", it changes stdin for the program to a file descriptor for file.txt, so when the program attempts to read from stdin, instead of reading from user input entered into the terminal, it will read from the file. So basically, you ARE using a file handle when you read from a file in that manner.

AcrossFiveJulys
Profile Blog Joined September 2005
United States3612 Posts
Last Edited: 2009-10-17 03:45:46
October 17 2009 03:45 GMT
#26
Also, to the OP, it seems suspicious that you managed to write 100% working code to accomplish this task without even understanding that you need to print something out if you want to see the result.
Shade692003
Profile Joined August 2005
Canada702 Posts
October 17 2009 03:49 GMT
#27
On October 17 2009 12:19 vAltyR wrote:
Show nested quote +
cin >> ch;


You're reading in from a file, not the command prompt. You need to use file IO commands instead of cin.

Show nested quote +
while ( cin )
{...}


That's not going to work. You need some kind of boolean logic statement there. Typically what I've done in my C++ class is we have a sentinel character and then loop until the sentinel character. I'm surprised that even compiled... Hmmm...

Yeah, didn't compile for me. Did it compile for you?


Yes it will work. The while will loop until there is no characters to be read anymore. Well I think.
I hate the post below mine because it feels War3-ish.
SonuvBob
Profile Blog Joined October 2006
Aiur21550 Posts
October 17 2009 03:54 GMT
#28
On October 17 2009 12:45 AcrossFiveJulys wrote:
Also, to the OP, it seems suspicious that you managed to write 100% working code to accomplish this task without even understanding that you need to print something out if you want to see the result.

lol yeah.. and posting screenshots of running the thing first, only posting the code as an afterthought.
Administrator
eMbrace
Profile Blog Joined January 2009
United States1300 Posts
Last Edited: 2009-10-17 04:04:12
October 17 2009 04:02 GMT
#29
On October 17 2009 12:45 AcrossFiveJulys wrote:
Also, to the OP, it seems suspicious that you managed to write 100% working code to accomplish this task without even understanding that you need to print something out if you want to see the result.


lol well, it didn't decode the capital 'Y's properly (turned them into '?'s) -- but w/e I submitted it.

i asked my TA for help earlier and he got me on the right path, but he also confused me as to if I needed a cout statement (he erased my previous ones) -- so I forgot about it until now =p

a silly mistake, I usually code alright, although this was a harder thing to do and i forgot something really simple.
onmach
Profile Blog Joined March 2009
United States1241 Posts
October 17 2009 04:58 GMT
#30
You should realize that it is going to get a lot harder very quickly. It is important that you actually understand what you did and how this program actually works. If you don't you'll be beating your head against the wall later when you get to the chapters on streams and pointer arithmetic.

Also I hope your instructor is not teaching you this lousy coding style. Some of that is the problem of this forum, but it is no wonder you lost track of a statement with such verbose coding style.

+ Show Spoiler +

char ch, change;

while (cin >> ch) {

if (isalpha(ch)) change = reverseCaesar(ch);
else if (ispunct(ch)) change = convPunct(ch);
else if (isdigit(ch)) change = convDigit(ch);
else change = convRest(ch);

cout << change;
}


Only with decent indentation. You get the idea. I know my former instructors deducted as much as 30% if your code looked extremely bad. This was a good thing because once you get a job, if your code is hard for others to maintain, you will be marginalized into unpleasant projects.
eMbrace
Profile Blog Joined January 2009
United States1300 Posts
October 17 2009 05:37 GMT
#31
On October 17 2009 13:58 onmach wrote:
You should realize that it is going to get a lot harder very quickly. It is important that you actually understand what you did and how this program actually works. If you don't you'll be beating your head against the wall later when you get to the chapters on streams and pointer arithmetic.

Also I hope your instructor is not teaching you this lousy coding style. Some of that is the problem of this forum, but it is no wonder you lost track of a statement with such verbose coding style.

+ Show Spoiler +

char ch, change;

while (cin >> ch) {

if (isalpha(ch)) change = reverseCaesar(ch);
else if (ispunct(ch)) change = convPunct(ch);
else if (isdigit(ch)) change = convDigit(ch);
else change = convRest(ch);

cout << change;
}


Only with decent indentation. You get the idea. I know my former instructors deducted as much as 30% if your code looked extremely bad. This was a good thing because once you get a job, if your code is hard for others to maintain, you will be marginalized into unpleasant projects.


thanks for the advice
Prev 1 2 All
Please log in or register to reply.
Live Events Refresh
Next event in 11h 52m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Lowko527
ProTech133
StarCraft: Brood War
Shuttle 1940
Larva 1340
Soma 845
Hyuk 711
Light 700
Stork 593
BeSt 506
actioN 396
Snow 384
hero 253
[ Show more ]
Soulkey 223
910 166
Zeus 160
Rush 149
Barracks 104
Pusan 84
zelot 39
scan(afreeca) 29
Shinee 29
Free 28
Terrorterran 21
soO 21
Aegong 17
ajuk12(nOOB) 17
yabsab 12
Sacsri 11
SilentControl 10
Oya187 8
Dota 2
qojqva3061
Gorgc2867
Dendi517
XcaliburYe110
Counter-Strike
fl0m3975
zeus1206
Clem_sc2542
oskar71
Heroes of the Storm
Khaldor153
Other Games
singsing2620
B2W.Neo1155
hiko821
Mew2King595
crisheroes528
Happy291
ArmadaUGS219
Hui .204
RotterdaM184
XaKoH 95
djWHEAT67
QueenE66
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Michael_bg 4
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2262
• WagamamaTV373
• Noizen36
League of Legends
• TFBlade445
Upcoming Events
Korean StarCraft League
11h 52m
CranKy Ducklings
18h 52m
WardiTV 2025
20h 52m
SC Evo League
21h 22m
IPSL
1d 1h
Dewalt vs ZZZero
BSL 21
1d 4h
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
1d 6h
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
1d 18h
WardiTV 2025
1d 20h
OSC
1d 23h
[ Show More ]
IPSL
2 days
Bonyth vs KameZerg
BSL 21
2 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
2 days
Wardi Open
2 days
StarCraft2.fi
3 days
Monday Night Weeklies
3 days
Replay Cast
3 days
WardiTV 2025
3 days
StarCraft2.fi
4 days
PiGosaur Monday
4 days
StarCraft2.fi
5 days
Tenacious Turtle Tussle
5 days
The PondCast
5 days
WardiTV 2025
5 days
StarCraft2.fi
6 days
WardiTV 2025
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
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 © 2025 TLnet. All Rights Reserved.