• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 06:38
CET 12:38
KST 20:38
  • 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
Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3
Community News
Starcraft, SC2, HoTS, WC3, returning to Blizzcon!11$5,000+ WardiTV 2025 Championship4[BSL21] RO32 Group Stage3Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win9
StarCraft 2
General
RotterdaM "Serral is the GOAT, and it's not close" Starcraft, SC2, HoTS, WC3, returning to Blizzcon! Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win 5.0.15 Patch Balance Hotfix (2025-10-8) TL.net Map Contest #21: Voting
Tourneys
Constellation Cup - Main Event - Stellar Fest Merivale 8 Open - LAN - Stellar Fest $5,000+ WardiTV 2025 Championship Sea Duckling Open (Global, Bronze-Diamond) $3,500 WardiTV Korean Royale S4
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review [BSL21] RO32 Group Stage Practice Partners (Official) [ASL20] Ask the mapmakers — Drop your questions
Tourneys
BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION [ASL20] Grand Finals Small VOD Thread 2.0 The Casual Games of the Week Thread
Strategy
Current Meta How to stay on top of macro? PvZ map balance Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV Nintendo Switch Thread ZeroSpace Megathread General RTS Discussion Thread
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread YouTube Thread Things Aren’t Peaceful in Palestine Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Why we need SC3
Hildegard
Career Paths and Skills for …
TrAiDoS
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1421 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
Aiur21549 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
The PondCast
10:00
Episode 70
CranKy Ducklings63
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
OGKoka 243
StarCraft: Brood War
Sea 2232
GuemChi 1946
Jaedong 1927
Flash 996
firebathero 581
Pusan 400
Leta 250
Stork 232
Soma 217
Last 173
[ Show more ]
Hyun 160
Light 156
Killer 89
Barracks 88
hero 77
Snow 67
ToSsGirL 64
Rush 64
Mong 58
Backho 58
ZerO 58
Shine 53
JulyZerg 48
Sharp 39
Movie 35
zelot 23
Noble 19
scan(afreeca) 12
Terrorterran 10
IntoTheRainbow 9
Icarus 9
sSak 0
Dota 2
BananaSlamJamma195
XcaliburYe157
League of Legends
Reynor79
Counter-Strike
x6flipin434
zeus256
edward64
oskar1
Other Games
summit1g15153
singsing1338
crisheroes225
XaKoH 142
B2W.Neo131
Mew2King72
Happy24
ZerO(Twitch)4
Organizations
Counter-Strike
PGL161
StarCraft: Brood War
lovetv 6
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• StrangeGG 21
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 10
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos2403
• Stunt725
Other Games
• WagamamaTV123
Upcoming Events
LAN Event
3h 22m
OSC
10h 22m
Replay Cast
11h 22m
OSC
1d
LAN Event
1d 3h
Korean StarCraft League
1d 15h
CranKy Ducklings
1d 22h
WardiTV Korean Royale
2 days
LAN Event
2 days
IPSL
2 days
dxtr13 vs OldBoy
Napoleon vs Doodle
[ Show More ]
BSL 21
2 days
Gosudark vs Kyrie
Gypsy vs Sterling
UltrA vs Radley
Dandy vs Ptak
Replay Cast
2 days
Sparkling Tuna Cup
2 days
WardiTV Korean Royale
3 days
LAN Event
3 days
IPSL
3 days
JDConan vs WIZARD
WolFix vs Cross
BSL 21
3 days
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
3 days
Wardi Open
4 days
WardiTV Korean Royale
5 days
Replay Cast
5 days
Kung Fu Cup
6 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
6 days
The PondCast
6 days
RSL Revival
6 days
Solar vs Zoun
MaxPax vs Bunny
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025

Upcoming

BSL Season 21
SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
Stellar Fest
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 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.