| | |
array problems
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
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: Dec 2004
Posts: 489
Reputation:
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?
did you try this
C++ Syntax (Toggle Plain Text)
char buffer[6]; for(int i = 0; i < 5; i++) cin >> buffer[i]; buffer[5] = 0; cout << buffer << endl;
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
•
•
•
•
Originally Posted by Ancient Dragon
did you try this
C++ Syntax (Toggle Plain Text)
char buffer[6]; for(int i = 0; i < 5; i++) cin >> buffer[i]; buffer[5] = 0; cout << buffer << endl;
user enters A
konsole windows prints A
user enters B
konsolewindow prints AB
By "user enters A" what exactly do you mean? one character? a whole string of characters? a number?
C++ Syntax (Toggle Plain Text)
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: 489
Reputation:
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....
C++ Syntax (Toggle Plain Text)
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?
![]() |
Similar Threads
- 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
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






