Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 26th, 2005, 4:41 PM   #11
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Yup:
INSTEAD OF
char note[999];
DO
std::string note;
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 26th, 2005, 4:46 PM   #12
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
Complier messes up... it doesnt recognize string

`::string' undeclared (first use here)
`note' undeclared (first use this function)

void addNote() {
cout << "Enter the text for the note: ";
std::string note;
cin.ignore();
gets ( note );
cout << note;
}

Is that what you meant? I also tried string without std:: (because I have using namespace std but I got the same errors, is there a header file I need or something?
brokenhope is offline   Reply With Quote
Old Apr 26th, 2005, 4:58 PM   #13
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Oh... sorry - forgot about that:
#include <string>
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 26th, 2005, 6:59 PM   #14
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
Hmm I get the same errors after including it still...

EDIT

oops I didnt know there was a diffrence between string.h and string I thought they were the same and you just put the .h ending depending on your compiler.

gets ( ); doesnt work now, it says it cant convert string to *char.

EDIT

getline (cin, note);

worked, and now everything so far is working, now I want to make a wordwrap which im sure will be hella hard to do, but the text spacing out as odd as it is right now, half of a word on one like and 2 letters on the next is getting annoying, and starting a line out with a space is getting annoying... so is it even worth it to try to write a word wrapper?

Last edited by brokenhope; Apr 26th, 2005 at 8:08 PM.
brokenhope is offline   Reply With Quote
Old Apr 27th, 2005, 12:34 PM   #15
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Why not?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 27th, 2005, 5:59 PM   #16
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
Why not make one? I really have no clue how to... since im still new to C++ I still dont know any methods of how to do things.

I was thinking I would have to put the string through a loop and it seperated the string into temporary strings (each temp string containing one line), and it inserts a word to the end of the array one by one if it will fit on the line, and it goes through the whole string of words doing that... but I still dont know how to tell if the word fits or not, or even how to make this, or if its even sloppy coding, or the only way there is to do it 0_o.
brokenhope is offline   Reply With Quote
Old Apr 27th, 2005, 6:23 PM   #17
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Here's an idea: split the string into an array, separated by spaces. For example:
string words[] = {"The", "quick", "brown", "fox"};
You'd have to use pointers to do this, unfortunately. Next, just keep outputting and recording how many characters you've used, and add a new line whenever you need to. Generally, the console's 80 characters across.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 27th, 2005, 7:05 PM   #18
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
hmm Im horrible with pointers, just recently learned them and I still dont understand how theyd be useful in this situation, ill look up in the refrence librarys at cplusplus.com for any functions I can use since im drawing a blank on how to even get it into an array, and I cant really hand type each array. But I still dont know how to do the pointer stuff.
brokenhope is offline   Reply With Quote
Old Apr 28th, 2005, 1:12 PM   #19
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
That's what I'm saying - you need pointers to get it into the array:
// loop through and count the number of spaces:
int count = 0;
for (int i = 0; note[i]; i++)
{
    if (note[i] == 0x20)
    {
        count++;
    }
}

// declare a new array with that many items plus one
string *words = new string [count + 1];

int lastSpace = -1;
count = 0;

for (int i = 0; note[i]; i++)
{
    if ((note[i] == 0x20))
    {
        *(words + count) = note.substr(lastSpace + 1, i - lastCount + 1);
        count++;
    }
}
*(words + count) = note.substr(lastSpace + 1, note.length());
That'll load 'em into an array (hopefully - it hasn't been tested).
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 29th, 2005, 1:30 AM   #20
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
one of the classic uses of pointers in the C language is to have arrays of pointers for string manipulation. because of the way C handles strings as arrays of characters you need this sort of dynamic array of arrays approach for this. this is one of the reasons i think everyone should learn C at least to the point where strings and arrays and pointers come together. it gives you a better understanding od programmming in general. every once in a while i quit learning C++ to rebuild and strengthen my mad crazy C $ki11Z dawg. w00t!
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:55 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC