Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 12-20-2006, 10:07 AM   #1
Baseband Member
Dnsgm's Avatar
Join Date: Jan 2006
Posts: 61
Default c++ strings

I'm having some troubles with some strings in c++. heres my code:

#include <iostream>
#include <fstream>
using namespace std;

int main ()
    string work;
    cin >> work;
    cout << work;
    ofstream myfile;
    myfile.open ("example.html");
    myfile << "<html>\n";
    myfile << "<head>\n";
    myfile << "<title>";
    myfile << "hello";
    myfile << "</title>\n";
    myfile << "</head>\n";
    myfile << "<body>\n";
    myfile << "<font size=45>";
    myfile << work;
    myfile << "</font>\n";
    system ("pause");
    return 0;

I want to output a sentence but it only outputs the first word, so i need some help their.


Dnsgm is offline   Reply With Quote
Old 12-20-2006, 02:30 PM   #2
Baseband Member
Griz803's Avatar
Join Date: Jun 2004
Posts: 89
Default Re: c++ strings

Okay, I think I see a couple of things that you may or may not be having trouble with in your code. First, I'm not sure why you got away without the statement
"#include <string>" in your code. I'd definitely change that first. Then, to be sure that I get what I need for file manipulations forget about the
"#include <ofstream>" or "#include <ifstream>" thing. The best way to do that is to use the easier and all inclusive "#include <fstream>". It does both and won't add pounds to a program unneccessarily

You then have several options to correct the errant output / input with a string. I'll direct you first to the favorite C and C++ reference URL,

It can be used for almost all your C / C++ lookup needs. And it is correct on all points and occasions that I've used it.

Next, I will direct you to a few specific pages that will add to your C++ I/O prowess from within that site. Don't get confused, there is more than one
possible solution and that is a very C / C++ thing in itself. Here you go:







Okay, that isn't as much reading as it seems. Give it a look, especially the last three. If the light bulb doesn't go off, then repost what is happening after your next attempt and I'll show some functional code for it. Good luck and think about the string object.
/*What does not kill us, makes us drink far too much caffeine*/
Griz803 is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 11:17 AM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0