yes the double dimension table would be a good idea..
is your code correct??it seems strange to me..for example char[0][i]==null
did you mean newword[0][i]==null?
and another question is how can i clear the cin
for example
if it waits that three strings come and come only two how can make it not wait for the third?
can i with some way go to the end of the command line input??
so that the next cin doesnt see something in the command line and so it will wait new entry
Actually in our school ,we are only required to use one library and that's <iostream.h>,with this one library we are still able to make programs that are unexpectedly amazing ,well I'm just a newbie with c++ but then, I'm just going to make some corrections with the program gaved by stewbond ,with that program ,the user is required to input 1000 characters, what if let's place a condition to make the inputting of characters by the user stop. Let's say inputting of character will stop if the user enter #0.
1 2 3 4 5 6 7 8 9
#include<iostream.h>
void main()
{
char a[25];
cout<<"Enter #0 if you want to stop inputting characters";
do{
cin>>a;
}while(a!=0); //condition stands as a stopper of the program.
}
can i with some way go to the end of the command line input?? so that the
next cin doesnt see something in the command line and so it will wait new entry
[EDIT]
vagelis wrote:
so how can i check if i am at the end of
the cin? and how can i clear the cin??
[/EDIT]
What do you mean? Can you give a concrete example of the problem you
have? What do you want your program to do, and what does it do instead?
#include <iostream>
#include <string>
#include <vector>
usingnamespace std;
int main()
{
string word;
vector<string> words;
// CTRL-Z and then ENTER to stop
while (cin >> word) words.push_back(word);
cin.clear();
cout << "\nyour words are:\n\n";
for (unsigned i = 0; i < words.size(); ++i)
cout << words[i] << endl;
return 0;
}
If you hit CTRL-Z and then ENTER, cin.eof() will return true and your while
loop will stop. Just remember to also add a cin.clear() call after your loop.
but i dont want to do it for my self to run
i want always with enter when i give three strings not to go inside the loop
but if i give more than three to go inside the loop and get more strings
i see that cin's cursor for a reason has returned at the beginning at letter 'a' of the word alpha..
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
usingnamespace std;
int main()
{
vector<string> words;
string word;
string line;
// get the whole line ...
getline(cin, line);
// ... then use it to create
// a istringstream object ...
istringstream buffer(line);
// ... and then use that istringstream
// object the way you would use cin
while (buffer >> word) words.push_back(word);
cout << "\nyour words are:\n\n";
for (unsigned i = 0; i < words.size(); ++i)
cout << words[i] << endl;
}