i have jut started learning cpp need help :
is their any way i can make a char statement conatining spaces too.
if yes plz tell me.
:rolleyes:
The reason your address stops at the first space is that the extraction operator (cin >>) reads a single whitespace-delimited token. Several helpful replies already pointed this out: suggested using a line-reading function, showed a cin.getline approach for fixed buffers, noted that string literals can include spaces, and spotted that the c0s.obj error comes from an old/misconfigured compiler setup. Below is a modern, safer pattern you can use and a few troubleshooting tips.
#include <iostream>
#include <string>
int main() {
std::string address;
std::cout << "Enter your address: ";
std::getline(std::cin, address); // reads the whole line, including spaces
std::cout << "Your address is: " << address << '\n';
return 0;
} Notes and common pitfalls:
cin >> someToken; before getline, the leftover newline will make getline return an empty string. Clear it first with:std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); (add #include <limits>).std::string + std::getline over fixed char[] buffers to avoid overflow and manual size management.conio.h, clrscr() or getch() for portable code; they’re from old Turbo/Borland environments.If you saw “unable to open file 'c0s.obj'” that typically means an outdated Borland/Turbo toolchain or misconfigured library paths. The robust fix is to switch to a standards-compliant compiler/IDE (e.g., GCC/MinGW, Clang, or Visual Studio) or use an online C++ compiler for learning. This will remove many environment-specific errors and let the examples above work as shown.
Jump to Post— Dave Sinkula 2,398is their any way i can make a char statement conatining spaces too.
What question are you trying to ask? The best I can manage is, "How can a read a line of text containing whitespace from the user?" If so, my next question would be, C or C++?
Jump to Post— Dave Sinkula 2,398Look up getline -- cin is whitespace delimited.
Jump to Post— Asif_NSU 25I edited your code, good for tc only...
# include <iostream.h> # include <conio.h> void main() { clrscr(); char address[60]; cout<<"Enter your address"; cin.getline(address,60,'\n'); cout<<"Your address is "<<address; getch(); }
i got tc.exe
is their any way i can make a char statement conatining spaces too.
What question are you trying to ask? The best I can manage is, "How can a read a line of text containing whitespace from the user?" If so, my next question would be, C or C++?
I think s/he is trying to declare a variable "char" to values seperated by spaces. If so, you can simply do this:
char a[] = "Blue Moon";
Just replace "a" with the variable you want to use, and replace the words in quotation marks with your own statement. Hope this helps.
i accually need help wwith this programm
here i want help so that any amount of words can be filled in the address
# include <iostream.h>
# include <conio.h>
void main()
{
clrscr();
char address[60];
cout<<"Enter your address";
cin>>address;
cout<<"Your address is "<<address;
getch();
} << moderator edit: added code tags: [code][/code] >>
Look up getline -- cin is whitespace delimited.
im relly a noob i dont know anything i just started learning c++
can u help me by editing my above program .
I edited your code, good for tc only...
# include <iostream.h>
# include <conio.h>
void main()
{
clrscr();
char address[60];
cout<<"Enter your address";
cin.getline(address,60,'\n');
cout<<"Your address is "<<address;
getch();
} simple examlpe of getline:
char input[55];
cin.getline(input,55); its showing a error
unable to open file "c0s.obj"
wut does it mean :eek:
It's trying to tell you to replace your old ass compiler with something that conforms to the C++ standard. Let me guess, your operating system is Windows XP, right?
>unable to open file "c0s.obj"
Go to Options, Directories and make sure that you see something like this sitting around there: c:\<wherever you installed it>\lib
THANK YOU Everyone for your suppeort
when i tried the same thing today it was not showing the error (hmmm.......)
THANKS:-)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.