does anybody knows how to write multilines with cstring library, id like to know for example do a program that in wich you can write many lines of text but if you press enter i dont want it close the program id like to still running the program until you write "0" or "QUIT" and out put the same text as you wrote.
Also, why do you want to use C-style strings? You have to continually create a larger buffer and copy the old string into the new buffer; it's a real pain and easy to get wrong.
#include <iostream>
#include <cstring>
usingnamespace std;
int main(){
chat string[999+1];
cout << "Enter a text(press 0 to quit)";
/*I wanted to enter a text in wich still writing the same string while pressing enter
even though it doesn't work,
when I press enter the program just close and gives me the first line*/
while(true){
cin.getline(string, 999);
if(strcmp(string, "0"))
break;
}
cout << string << endl;
return 0;
}
strcmp returns 0 if the two strings are equal.
You're comparing the two strings and breaking if they're not equal.
In any case, the output of your program will be the last string you entered (since you overwrite your string with the new input each time).
If you don't want that, then C strings are really not the best way to go, since you'd have to allocate the strings yourself and resize them from time to time....
Thank you , i just wanted.to.know that answer, i know.jow to.do it with.string library, but just.wanted.to make.sure.if.i could.do it with cstring library, but.now.i know.i cant.do it.with a.simple.character, only if.you size.it.with.an array