![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Yup:
INSTEAD OF char note[999]; DO std::string note; |
|
|
|
|
|
#12 |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 126
Rep Power: 4
![]() |
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? |
|
|
|
|
|
#13 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Oh... sorry - forgot about that:
#include <string> |
|
|
|
|
|
#14 |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 126
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#15 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Why not?
|
|
|
|
|
|
#16 |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 126
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#17 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Here's an idea: split the string into an array, separated by spaces. For example:
string words[] = {"The", "quick", "brown", "fox"}; |
|
|
|
|
|
#18 |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 126
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#19 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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()); |
|
|
|
|
|
#20 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|