Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 04-06-08   #1 (permalink)
Security Sleuth
 
Pooping^fish's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: oklahoma
Posts: 907

Rep: 44 Pooping^fish is acknowledged by some
Unique Rep: 40
Trader Rating: 2
Default cin.getline being skipped?

New problem now! Fuapa and dee de dee! I wrote basically all or most of my program and so far so good..buttt one random line where it cin's "body" gets skipped. It asks the question and skips to the next question. Frustrated, it produces no errors.. Ideas?

Code:
#include <string>
#include <iostream>
#include <fstream>

using namespace std; 

int main()
{
   char filename[51]; //filename to be stored
   char title[51]; //page title
   char body[301]; //body text
   char comments[75]; //extra raw code input
   ofstream the_file;

   cout <<"What do you want the name of your webpage to be? NOT the title! Dont forget to add the .html extension! \n"; 
   cin.getline(filename, 50, '\n');
   the_file.open(filename);
   
   
   the_file << "<html>"; //start html code
   
   string titlea = ("<title>");
   string titleb = ("</title>");
    
   cout <<"What do you want the title to be? \n"; //page title
   cin.getline(title, 50, '\n');
   the_file << titlea << title << titleb; //write page tags and title
   
   cout <<"What color do you want the background to be? Generic colors. You can also use an image in the same directory or specify an image in another directory. \n";
   string bg1 = ("<body bgcolor=");
   string bg2 = (">");
   string bg;
   cin >> bg;
   the_file << bg1<< bg<< bg2; //write body color tags and color
   
  
   cout <<"What do you want the body text of your page to be?"; //take in body text..cout is presented but getline is skipped so there is no input. Ehh?
   cin.getline(body, 300, '\n');
   
   cout <<"Do you want your text centered? 'yes' or 'no'. \n"; //Whether to center body text or not. Check over soon and clean.
   string align;
   cin >> align;
    if    (align == "yes") //center
    
    { 
   string body1 = ("<body>");
   string body2 = ("</body>");
   string div1 = ("<div align=center>");
   string div2 = ("</div>");
   
   the_file << div1 << body1;
   the_file << body;
   the_file << div2 << body2;
   }
   
   if (align == "no"); //dont center
   {
   string body1 = ("<body>");
   string body2 = ("</body>");
   the_file << body1 << body <<body2;       
   }
   
   cout <<"What do you want your text color to be? If none specified it will be black. \n";
   string textcolor;
   string text1 = ("<font color=");
   string text3 = ("</font>");
   string text2 = (">");
   cin >> textcolor;
   the_file << text1 << textcolor << text2 << text3;
   
   
   cout <<"If there is any other html comments or RAW CODE you can enter it here: "; //Question again presented but skips input. Why?
   cin.getline(comments, 74, '\n');
   the_file << comments;
   
   
   the_file << "</html>"; //finish off html tags
   
   

   
   
   
   the_file.close();
   cout << "\n\n\nProgram by Fr0nAtZ!\n"; //ohhaimehellothar
   system("PAUSE");
   return 0;
}
I need to figure out why the body line and the comments line are being skipped.
I have the spaces problem fixed and write problem fixed of course.

Thanks all!
__________________
Quote:
"O, hai! Want som pRon? Dwnlod ths kodk frst. Its teh bst pRonz ever, we prmis." -GibbyGano
Proud Member of the Linux Gaming Community
I am your friend.

System: CSS Pwner
CPU
e6400 @ 3.2
Motherboard
p5n-t 780i
Memory
2gb ocz @ 900
Graphics Card
8800gtx
Hard Drive
7200.10 250gb
Sound Card
X-FI Extreme Music
Power Supply
750w Toughpower
Case
Lian li pc-65
CPU cooling
TRUE
GPU cooling
stock
OS
Arch Linux, XP for games
Monitor
24" Westy
Pooping^fish is offline   Reply With Quote
Old 04-06-08   #2 (permalink)
AMD Overclocker
 
decompiled's Avatar
 
amd nvidia

Join Date: Feb 2006
Location: Redsox Nation
Posts: 516

Rep: 50 decompiled is acknowledged by some
Unique Rep: 48
Hardware Reviews: 9
Trader Rating: 0
Default

Oh wait nevermind... I see what your saying... *edit*


You will need to clear your stream. Take a look at cin.clear() and cin.ignore().

The reason your code doesn't stop at the body and comments sections is because you still have your control characters in the cin buffer. Your newline char isn't getting cleared from your << call.

getline() removes the newline control character. << does not remove it.

System: Slow Poke
CPU
AMD X2 4400
Motherboard
MSI K8N Diamond +
Memory
3gb TCC5
Graphics Card
eVGA 7900GS
Hard Drive
74gb Raptor + Raid 1 640's
Sound Card
Audigy SE
Power Supply
OCZ 520 PowerStream
Case
Antec P180
CPU cooling
Stock AMD
GPU cooling
Stock eVGA
OS
Vista x64
Monitor
Dell 1905FP

Last edited by decompiled : 04-06-08 at 05:12 PM. Reason: oops
decompiled is offline   Reply With Quote
Old 04-07-08   #3 (permalink)
Chiefly Ignorant
 
Scriptorum's Avatar
 
intel nvidia

Join Date: Jan 2008
Location: Atlanta, GA
Posts: 54
Blog Entries: 12

Rep: 13 Scriptorum Unknown
Unique Rep: 10
Trader Rating: 0
Default

BTW, you should have only one body tag in your HTML document. All layout tags belong inside the body tag, not outside. For example:

Code:
<html>
   <head>
      ...all head tags go in here (title, etc)
   </head>
   <body bgcolor=xxxxx>
      ... ALL displayable content goes here
   </body>
</html>
__________________
Quote:
Originally Posted by The Bartender Paradox View Post
crazy?...nah. when you cool with a fire extinguisher then your crazy.

System: Flaming Moe's MacBook Pro
CPU
Core 2 Duo
Motherboard
MacBook Pro
Memory
4GB DDR2-667
Graphics Card
512Mb NVIDIA GeForce 8600M GT
Hard Drive
200Gb 7200RPM
OS
OSX 10.5.2 / XP Pro / Boot Camp + Parallels
Monitor
17" Matte 1920x1200
Scriptorum is offline Overclocked Account   Reply With Quote
Old 04-07-08   #4 (permalink)
Security Sleuth
 
Pooping^fish's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: oklahoma
Posts: 907

Rep: 44 Pooping^fish is acknowledged by some
Unique Rep: 40
Trader Rating: 2
Default

Oh, really?
Weird. Well I got it finished with a lot of help from a friend. Lots of problems encountered during this.
__________________
Quote:
"O, hai! Want som pRon? Dwnlod ths kodk frst. Its teh bst pRonz ever, we prmis." -GibbyGano
Proud Member of the Linux Gaming Community
I am your friend.

System: CSS Pwner
CPU
e6400 @ 3.2
Motherboard
p5n-t 780i
Memory
2gb ocz @ 900
Graphics Card
8800gtx
Hard Drive
7200.10 250gb
Sound Card
X-FI Extreme Music
Power Supply
750w Toughpower
Case
Lian li pc-65
CPU cooling
TRUE
GPU cooling
stock
OS
Arch Linux, XP for games
Monitor
24" Westy
Pooping^fish is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 02:58 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.28284 seconds with 8 queries