#include <iostream>
#include <iomanip>
#include <string>
int main()
{
std::string str ;
std::cin >> str ; // enter 123456789
std::cout << str << '\n' ; // 123456789
std::cin >> std::setw(3) >> str ; // enter 123456789
// reads "123", "456789\n" remains in the input buffer
std::cout << str << '\n' ; // 123
char cstr[32] ;
std::cin >> std::setw(3) >> cstr ; // we don't need to enter anything; "456789\n" is in the input buffer
// reads "45" from the input buffer, and appends a null character as the third character
// "6789\n" remains in the input buffer
std::cout << cstr << '\n' ; // 45
std::cin >> std::setw(8) >> str ; // we don't need to enter anything; "6789\n" is in the input buffer
// reads four characters "6789", formatted input stops when a white space is encountered
// a new line character remains in the input buffer
std::cout << str << '\n' ; // 6789
int n ;
std::cin >> std::setw(4) >> n ; // enter 123456789
// setw (width) is ignored for numeric input, reads "123456789" into n
std::cout << n << '\n' ; // 123456789
}
I am not sure I read any of that correctly. It may still be early for me :-/
1 2 3 4 5 6 7 8 9
I am looking for print fields. ie.
int exp;
cout<<"example here"<<setw(7)<<exp;
example here _ _ _ _ _ exp
or is that all wrong?
But aligning the Cin so its to the right
What do you want to print? And what should the output look like?
You need to give an example with actual data to be printed and the desired output format.