string problem

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream.h>

int main(){
	char first[]="1234567890";
	char second[]="0000000000";
	for (int i=1;i<=10;i++){
		second[i] = first[i];
	}
	cout << second;

	return 0;
}


Why is the output 0234567890?
But not 1234567890?
Array indices start from 0 and go up to size-1, not from 1 to size
Because you have for (int i=1 ....

if you make it for (int i=0 ... it'll compile and output what you want...

EDIT:

I guess thats the same as Bazzy said, but then in my noob language :P

EDIT:

and by the way, why not use iostream? the .h version is outdated (and the C version right?)
Last edited on
iostream.h is pre-standard C++
Thank you very much, Bazzy and kaduuk.
I understood now.

Replying kaduuk,
#include <iostream.h>
isn't the same as
1
2
#include <iostream>
using namespace std;
?
<iostream.h> is pre-1998
<iostream>+std is standard C++
very quick reply!
just use #include <iostream.h> to save time.
Modern compilers will reject that. You should follow the standards
follow you.
thx all.
Topic archived. No new replies allowed.