• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 16:51
CEST 22:51
KST 05:51
  • 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
TL.net Map Contest #21: Voting4[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
Weekly Cups (Oct 6-12): Four star herO65.0.15 Patch Balance Hotfix (2025-10-8)74Weekly Cups (Sept 29-Oct 5): MaxPax triples up3PartinG joins SteamerZone, returns to SC2 competition325.0.15 Balance Patch Notes (Live version)119
StarCraft 2
General
5.0.15 Patch Balance Hotfix (2025-10-8) The New Patch Killed Mech! TL.net Map Contest #21: Voting Ladder Impersonation (only maybe) Weekly Cups (Oct 6-12): Four star herO
Tourneys
LiuLi Cup - September 2025 Tournaments Sparkling Tuna Cup - Weekly Open Tournament Master Swan Open (Global Bronze-Master 2) Tenacious Turtle Tussle WardiTV Mondays
Strategy
Custom Maps
External Content
Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers Mutation # 492 Get Out More
Brood War
General
Whose hotkey signature is this? BW caster Sayle BW General Discussion Pros React To: BarrackS + FlaSh Coaching vs SnOw ASL20 General Discussion
Tourneys
[Megathread] Daily Proleagues [ASL20] Semifinal B [ASL20] Semifinal A [ASL20] Ro8 Day 4
Strategy
Current Meta BW - ajfirecracker Strategy & Training Siegecraft - a new perspective TvZ Theorycraft - Improving on State of the Art
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread ZeroSpace Megathread Dawn of War IV Path of Exile
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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
SPIRED by.ASL Mafia {211640} TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Men's Fashion Thread Sex and weight loss
Fan Clubs
The herO Fan Club! The Happy Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
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
Inbreeding: Why Do We Do It…
Peanutsc
From Tilt to Ragequit:The Ps…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1269 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
Next event in 2h 9m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 594
IndyStarCraft 121
JuggernautJason76
ProTech73
Railgan 59
Codebar 34
PiGStarcraft11
StarCraft: Brood War
Larva 318
Leta 244
Dewaltoss 114
ZZZero.O 48
sas.Sziky 30
NaDa 29
Dota 2
PGG 112
LuMiX1
Counter-Strike
shoxiejesuss718
Stewie2K559
Foxcn264
Heroes of the Storm
Liquid`Hasu570
Other Games
FrodaN2117
fl0m619
byalli270
Skadoodle250
Pyrionflax159
Sick149
ViBE69
markeloff60
Trikslyr41
shahzam13
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• StrangeGG 16
• HeavenSC 5
• IndyKCrew
• LaughNgamezSOOP
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• Migwel
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• Ler105
• Noizen37
League of Legends
• Doublelift2976
• imaqtpie2201
Other Games
• Shiphtur305
• WagamamaTV293
Upcoming Events
OSC
2h 9m
Replay Cast
2h 9m
The PondCast
13h 9m
OSC
15h 9m
Wardi Open
1d 14h
CranKy Ducklings
2 days
Safe House 2
2 days
Sparkling Tuna Cup
3 days
Safe House 2
3 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
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
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 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.