#include<iostream>
#include<string>
#include<conio.h>
using namespace std;
int main(){
string array[5][5];
int i=0,j=0;
string z[5]={"abdg","ygur","guqh","asdf","sent"};
for(i=0;i<5;i++)
for(j=0;j<4;j++)
{ array[i][j]=z[i][j];
cout<<"\narr[][]="<<array[i][j];}
for(i=0;i<5;i++)
cout<<"\narr="<<array[i]<<endl; //this z not workin.WHY??...PLZ HELP!
getch();
return 0;
}
rdx05
0
Newbie Poster
Recommended Answers
Jump to PostHere, this sould fix it:
#include<iostream> #include<string> using namespace std; int main(){ char array[5][5]; int i=0,j=0; string z[5]={"abdg","ygur","guqh","asdf","sent"}; for(i=0;i<5;i++) for(j=0;j<4;j++){ array[i][j]=z[i][j]; cout<<"\narr["<<i<<"]["<<j<<"]="<<array[i][j]; } for (int i=0;i<5;i++) array[i][4]=0;//clears the buffer for unwanted characters. for(i=0;i<4;i++) cout<<"\narr="<<array[i]<<endl; return (0); }
I changed the array type to char, as ravenous …
Jump to PostAlso don't use #include <conio.h> and getch() because they are really really bad.
Read bad as non-standard and prone to cause problems for you when you start using one of the 99% of the compilers that don't know what
<conio.h>
andgetch()
are.The standard definition of bad …
Jump to PostIf you want to put every char of an array of strings inside another string array you can do it like this:
#include <iostream> #include <string> using namespace std; int main(){ string arr[5]; string str[5]={"aaaa", "bbbb", "cccc", "dddd", "eeee"}; for (int i=0;i<5;i++){ for (int j=0;j<4;j++) arr[i]+=(str[i][j]);//here arr[i] …
All 10 Replies
ravenous
266
Posting Pro in Training
Lucaci Andrew
140
Za s|n
rdx05
commented:
thanx a lot....
+0
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
rizwan93
0
Newbie Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
rdx05
0
Newbie Poster
Lucaci Andrew
140
Za s|n
rizwan93
0
Newbie Poster
Lucaci Andrew
140
Za s|n
rdx05
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.