• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 19:50
CEST 01:50
KST 08:50
  • 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 1 - Final Week6[ASL19] Finals Recap: Standing Tall15HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0
Community News
Esports World Cup 2025 - Brackets Revealed14Weekly Cups (July 7-13): Classic continues to roll8Team TLMC #5 - Submission extension3Firefly given lifetime ban by ESIC following match-fixing investigation17$25,000 Streamerzone StarCraft Pro Series announced7
StarCraft 2
General
Who will win EWC 2025? RSL Revival patreon money discussion thread The GOAT ranking of GOAT rankings Server Blocker Weekly Cups (July 7-13): Classic continues to roll
Tourneys
FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament Sea Duckling Open (Global, Bronze-Diamond) RSL: Revival, a new crowdfunded tournament series $5,100+ SEL Season 2 Championship (SC: Evo)
Strategy
How did i lose this ZvP, whats the proper response
Custom Maps
External Content
Mutation # 482 Wheel of Misfortune Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome
Brood War
General
Flash Announces (and Retracts) Hiatus From ASL BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion Soulkey Muta Micro Map? [ASL19] Finals Recap: Standing Tall
Tourneys
[Megathread] Daily Proleagues 2025 ACS Season 2 Qualifier Cosmonarchy Pro Showmatches CSL Xiamen International Invitational
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread CCLP - Command & Conquer League Project The PlayStation 5
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread We are Ready to Testify: Emergence Stop Killing Games - European Citizens Initiative
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Korean Music Discussion Movie Discussion! [Manga] One Piece Anime Discussion Thread [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023 NBA General Discussion NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Ping To Win? Pings And Their…
TrAiDoS
momentary artworks from des…
tankgirl
from making sc maps to makin…
Husyelt
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 590 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 10h 10m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
UpATreeSC 224
Nathanias 158
JuggernautJason68
CosmosSc2 63
Livibee 33
StarCraft: Brood War
ZZZero.O 87
Dota 2
monkeys_forever1005
NeuroSwarm128
canceldota22
League of Legends
Grubby4949
Trikslyr67
Counter-Strike
oskar252
Super Smash Bros
AZ_Axe122
Other Games
tarik_tv22843
summit1g12336
shahzam614
C9.Mang0230
ViBE160
Skadoodle135
PPMD45
Organizations
Other Games
gamesdonequick1716
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• RyuSc2 48
• Hupsaiya 48
• sitaska39
• musti20045 31
• davetesta27
• IndyKCrew
• AfreecaTV YouTube
• intothetv
• Kozan
• sooper7s
• LaughNgamezSOOP
• Migwel
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota21166
Other Games
• imaqtpie1993
Upcoming Events
CranKy Ducklings
10h 10m
Epic.LAN
12h 10m
CSO Contender
17h 10m
Sparkling Tuna Cup
1d 10h
Online Event
1d 16h
Esports World Cup
3 days
ByuN vs Astrea
Lambo vs HeRoMaRinE
Clem vs TBD
Solar vs Zoun
SHIN vs Reynor
Maru vs TriGGeR
herO vs Lancer
Cure vs ShoWTimE
Esports World Cup
4 days
Esports World Cup
5 days
Esports World Cup
6 days
Liquipedia Results

Completed

JPL Season 2
RSL Revival: Season 1
Murky Cup #2

Ongoing

BSL 2v2 Season 3
Copa Latinoamericana 4
Jiahua Invitational
BSL20 Non-Korean Championship
CSL Xiamen Invitational
CSL Xiamen Invitational: ShowMatche
Championship of Russia 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25

Upcoming

2025 ACS Season 2
CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
BSL Season 21
RSL Revival: Season 2
SEL Season 2 Championship
uThermal 2v2 Main Event
FEL Cracov 2025
Esports World Cup 2025
Underdog Cup #2
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
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.