• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 00:57
CEST 06:57
KST 13:57
  • 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 TLMC #5 - Finalists & Open Tournaments0[ASL20] Ro16 Preview Pt2: Turbulence10Classic Games #3: Rogue vs Serral at BlizzCon9[ASL20] Ro16 Preview Pt1: Ascent10Maestros of the Game: Week 1/Play-in Preview12
Community News
Weekly Cups (Sept 8-14): herO & MaxPax split cups4WardiTV TL Team Map Contest #5 Tournaments1SC4ALL $6,000 Open LAN in Philadelphia8Weekly Cups (Sept 1-7): MaxPax rebounds & Clem saga continues29LiuLi Cup - September 2025 Tournaments3
StarCraft 2
General
#1: Maru - Greatest Players of All Time Weekly Cups (Sept 8-14): herO & MaxPax split cups Team Liquid Map Contest #21 - Presented by Monster Energy SpeCial on The Tasteless Podcast Team TLMC #5 - Finalists & Open Tournaments
Tourneys
Maestros of The Game—$20k event w/ live finals in Paris SC4ALL $6,000 Open LAN in Philadelphia Sparkling Tuna Cup - Weekly Open Tournament WardiTV TL Team Map Contest #5 Tournaments RSL: Revival, a new crowdfunded tournament series
Strategy
Custom Maps
External Content
Mutation # 491 Night Drive Mutation # 490 Masters of Midnight Mutation # 489 Bannable Offense Mutation # 488 What Goes Around
Brood War
General
[ASL20] Ro16 Preview Pt2: Turbulence BW General Discussion ASL20 General Discussion Diplomacy, Cosmonarchy Edition BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[ASL20] Ro16 Group D [ASL20] Ro16 Group C [Megathread] Daily Proleagues SC4ALL $1,500 Open Bracket LAN
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread General RTS Discussion Thread Nintendo Switch Thread Borderlands 3
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread Russo-Ukrainian War Thread The Big Programming Thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023
World Cup 2022
Tech Support
Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s)
TL Community
BarCraft in Tokyo Japan for ASL Season5 Final The Automated Ban List
Blogs
The Personality of a Spender…
TrAiDoS
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1160 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
PiGosaur Monday
00:00
#49
Liquipedia
OSC
23:00
OSC Elite Rising Star #16
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft519
StarCraft: Brood War
Leta 571
Noble 54
ajuk12(nOOB) 41
Icarus 9
Dota 2
NeuroSwarm131
Counter-Strike
Stewie2K437
semphis_42
Super Smash Bros
Mew2King35
Other Games
summit1g4997
C9.Mang0310
XaKoH 152
ViBE143
SortOf48
Trikslyr33
Organizations
Other Games
gamesdonequick705
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• OhrlRock 94
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1160
• Rush1138
• Stunt424
Other Games
• Scarra1197
Upcoming Events
LiuLi Cup
6h 3m
OSC
14h 3m
RSL Revival
1d 5h
Maru vs Reynor
Cure vs TriGGeR
The PondCast
1d 8h
RSL Revival
2 days
Zoun vs Classic
Korean StarCraft League
2 days
BSL Open LAN 2025 - War…
3 days
RSL Revival
3 days
BSL Open LAN 2025 - War…
4 days
RSL Revival
4 days
[ Show More ]
Online Event
4 days
Wardi Open
5 days
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

Proleague 2025-09-10
Chzzk MurlocKing SC1 vs SC2 Cup #2
HCC Europe

Ongoing

BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
LASL Season 20
RSL Revival: Season 2
Maestros of the Game
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
FISSURE Playground #1

Upcoming

2025 Chongqing Offline CUP
BSL World Championship of Poland 2025
IPSL Winter 2025-26
BSL Season 21
SC4ALL: Brood War
BSL 21 Team A
Stellar Fest
SC4ALL: StarCraft II
EC S1
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries 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.