•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 425,904 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,867 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1647 | Replies: 8
![]() |
•
•
Join Date: Dec 2004
Posts: 465
Reputation:
Rep Power: 4
Solved Threads: 5
Hello boys and girls,
I'm wondering around with arrays and I'm trying to get one up so that it grabs a user inputt'd char and adds it on then prints out the contents of the array so far
ie "Enter character" :
User enters : 'A'
Prints out A on screen
"Enter character" :
User enters B
Printsout A and B on screen.
I've got no problem populating and printing out arrays, but I cant figure this one out.
I've thought adding to strings but no luck there.
I've got this so far but it doesnt help at all and I know why but not sure how to defeat this...
[code]
...
int i;
for (i = 0 ; 1 < 5 ; i++)
{
cin >> buffer[i];
}
for (i = 0 ; i < 5; i++)
{
cout << buffer[i]
}
whilst this code doesnt do what ask'd
I thought'd about how to get one step closer:
for (i = 0 ; 1 < 5 ; i++)
{
cin >> buffer[i];
{
for (i = 0 ; i < 5; i++)
{
cout << buffer[i]
}
}
}
but still fails....can anyone help us out here?
I'm wondering around with arrays and I'm trying to get one up so that it grabs a user inputt'd char and adds it on then prints out the contents of the array so far
ie "Enter character" :
User enters : 'A'
Prints out A on screen
"Enter character" :
User enters B
Printsout A and B on screen.
I've got no problem populating and printing out arrays, but I cant figure this one out.
I've thought adding to strings but no luck there.
I've got this so far but it doesnt help at all and I know why but not sure how to defeat this...
[code]
...
int i;
for (i = 0 ; 1 < 5 ; i++)
{
cin >> buffer[i];
}
for (i = 0 ; i < 5; i++)
{
cout << buffer[i]
}
whilst this code doesnt do what ask'd
I thought'd about how to get one step closer:
for (i = 0 ; 1 < 5 ; i++)
{
cin >> buffer[i];
{
for (i = 0 ; i < 5; i++)
{
cout << buffer[i]
}
}
}
but still fails....can anyone help us out here?
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,164
Reputation:
Rep Power: 38
Solved Threads: 930
•
•
Join Date: Dec 2004
Posts: 465
Reputation:
Rep Power: 4
Solved Threads: 5
•
•
•
•
Originally Posted by Ancient Dragon
what do you mean "it failes"? it won't compile? it won't run? what error(s) do you get? Note: unless its just a posting error, it needs a semicolor at the end of the cout line. Also, how is buffer declared?
The code compiles, butr I'm trying to reach a goal as stated above, could anyone hlep me out with it?
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,164
Reputation:
Rep Power: 38
Solved Threads: 930
did you try this
char buffer[6]; for(int i = 0; i < 5; i++) cin >> buffer[i]; buffer[5] = 0; cout << buffer << endl;
•
•
Join Date: Dec 2004
Posts: 465
Reputation:
Rep Power: 4
Solved Threads: 5
•
•
•
•
Originally Posted by Ancient Dragon
did you try this
char buffer[6]; for(int i = 0; i < 5; i++) cin >> buffer[i]; buffer[5] = 0; cout << buffer << endl;
Sorry to put a downer on things but I've built these, the next objective was to create something like this:
user enters A
konsole windows prints A
user enters B
konsolewindow prints AB
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,164
Reputation:
Rep Power: 38
Solved Threads: 930
By "user enters A" what exactly do you mean? one character? a whole string of characters? a number?
std::string buffer[5];
for(int i = 0; i < 5; i++)
{
cout << "Enter string #" << i+1;
getline(cin,buffer[i]);
}•
•
Join Date: Dec 2004
Posts: 465
Reputation:
Rep Power: 4
Solved Threads: 5
yes thats the one!
man a simple code seem'd so hard to do, thanks back to my game now....
why does it not register the first char input?
man a simple code seem'd so hard to do, thanks back to my game now....
char buffer[6];
for(int i=0;i<6;i++)
{
cin>>buffer[i];
cout << "\n";
for(int j=0;j<i;j++)
cout<<buffer[j];
}why does it not register the first char input?
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Array problems (C++)
- Array problems (C++)
- Problem installing XP on a SATA Striping Array (Storage)
- error 88:'(' expected when trying to display an array any help (Pascal and Delphi)
Other Threads in the C++ Forum
- Previous Thread: I Need A Willing C++ Programmer
- Next Thread: C++:three-digit number all odd, eve, or both



Linear Mode