Information required to format the output

Hi,
I was stuck in simple thing. Please don't mind replying for this simple stuff it will avoid wasting my time because already wasted a lot for the same .
If a string contains some 10 chars, but I want to display only 3characters per line, then what flag I need to set for achieving this output in cout ?

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <iomanip>
using namespace std;

int main () {
//  cout << setw (2) << "11111";  //tried this 
cout.flags(ios::left);
cout.width(10); // tried this
cout << "7777777777777777777777777777777777777" << endl;
  return 0;
}


Required O/p:
7777777777
7777777777
7777777777
7777777


but it is printing whole string in single line(7777777777777777777777777777777777777).
I understand setw/width() is not for this reason. But I googled but didn't get much info for this. Can anyone indicate me the exact function.
@sunilchintu2468
You could do it like this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;

int main ()
{
string line = "7777777777777777777777777777777777777";
int x, len;
len = line.length();

cout << "Displaying 10 characters per line.." << endl << endl;
for (x=1;x<len;x++)
{
	cout << line[x-1];
	if (x%10==0)
		cout << endl;
}

cout << endl << endl;
cout << "Now displaying only 3 characters per line.." << endl << endl;
for (x=1;x<len;x++)
{
	cout << line[x-1];
	if (x%3==0) // change number after mod sign (%) to specify how many characters per line
		cout << endl;
}

cout << endl << endl << endl;

return 0;
}
Yeah thanks for your valuable response. Thought any inbuild function is there in C++ instead of doing it manually. Anyhow I will use the same. Thanks a lot.
Topic archived. No new replies allowed.