| | |
Hey, I got a very simple program here. Yet the compiler is disagreeing with me.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2007
Posts: 7
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream.h> char first[ 20 ]; char middle[ 20 ]; char last[ 20 ]; main() { cout << "What is your name ScumBag? "; cin >> first >> "\n" >> middle >> "\n" >> last; return 0; }
The aggrevation in codding, is that it does what I ask it to do, not what I want it to do.
The serenity in an idea, is though I was beaten to the punch, I was also assured to be on-track.
The serenity in an idea, is though I was beaten to the punch, I was also assured to be on-track.
Re: Hey, I got a very simple program here. Yet the compiler is disagreeing with me.
0
#2 May 10th, 2007
•
•
Join Date: Apr 2007
Posts: 7
Reputation:
Solved Threads: 0
Re: Hey, I got a very simple program here. Yet the compiler is disagreeing with me.
0
#3 May 10th, 2007
Re: Hey, I got a very simple program here. Yet the compiler is disagreeing with me.
0
#4 May 10th, 2007
Re: Hey, I got a very simple program here. Yet the compiler is disagreeing with me.
1
#5 May 10th, 2007
>There is some syntax of cin that allowes us to ignore the \ns.. Isn't it?
You're probably thinking of the ws manipulator, but it discards all whitespace. If you want more control, you have to write your own manipulator:
And of course you can write custom manipulators so that they're used in exactly the same way as standard manipulators. This is only slightly more awkward than what the OP had before:
Of course, that's effectively a no-op because most formatted input discards leading whitespace by default. That's why removing those strings altogether still works as expected.
You're probably thinking of the ws manipulator, but it discards all whitespace. If you want more control, you have to write your own manipulator:
C++ Syntax (Toggle Plain Text)
class scan { public: scan ( const char *init ): fmt ( init ) {} friend istream& operator>> ( istream& in, const scan& s ) { while ( *s.fmt != '\0' && in && in.peek() == *s.fmt ) { in.get(); ++s.fmt; } if ( *s.fmt != '\0' ) in.setstate ( ios::failbit ); return in; } private: mutable const char *fmt; };
C++ Syntax (Toggle Plain Text)
cin>> first >> scan ( "\n" ) >> middle >> scan ( "\n" ) >> last;
I'm here to prove you wrong.
•
•
Join Date: Oct 2006
Posts: 3
Reputation:
Solved Threads: 0
Re: Hey, I got a very simple program here. Yet the compiler is disagreeing with me.
0
#6 May 10th, 2007
•
•
•
•
C++ Syntax (Toggle Plain Text)
#include <iostream.h> char first[ 20 ]; char middle[ 20 ]; char last[ 20 ]; main() { cout << "What is your name ScumBag? "; cin >> first >> "\n" >> middle >> "\n" >> last; return 0; }
Re: Hey, I got a very simple program here. Yet the compiler is disagreeing with me.
0
#7 May 10th, 2007
Re: Hey, I got a very simple program here. Yet the compiler is disagreeing with me.
0
#8 May 10th, 2007
•
•
•
•
C++ Syntax (Toggle Plain Text)
#include <iostream.h> char first[ 20 ]; char middle[ 20 ]; char last[ 20 ]; main() { cout << "What is your name ScumBag? "; cin >> first >> "\n" >> middle >> "\n" >> last; return 0; }
the problem is, you cant put escape sequences in input functions like cin>>, it should be like this..
cin>>first;
cout<<"\n";
cin>>middle;
cout<<"\n";
cin>>last;
there..you should use cout<< for escape sequences...
good luck!!
![]() |
Similar Threads
- Need advice & help with a very simple program (IT Professionals' Lounge)
- a simple C program to create/open/write/close files generaing basic arithmetic ops (C)
- Erroneus outputs in string manipulation simple program (C++)
- I am a girl doing my 1st simple program (C)
Other Threads in the C++ Forum
- Previous Thread: frustrated newbie needs help
- Next Thread: code optimization ...
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






