|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
cin.getline being skipped?
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | ||||||||||||||
|
Security Sleuth
|
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 have the spaces problem fixed and write problem fixed of course. Thanks all! ![]()
__________________
Quote:
Proud Member of the Linux Gaming CommunityI am your friend.
|
||||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
AMD Overclocker
|
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.
Last edited by decompiled : 04-06-08 at 05:12 PM. Reason: oops |
|||||||||||||
|
|
|
|
|
#3 (permalink) | ||||||||
|
Chiefly Ignorant
|
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>
__________________
|
||||||||
|
|
|
|
#4 (permalink) | ||||||||||||||
|
Security Sleuth
|
Oh, really?
Weird. Well I got it finished with a lot of help from a friend. Lots of problems encountered during this.
__________________
Quote:
Proud Member of the Linux Gaming CommunityI am your friend.
|
||||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|