int i;
    string *opening;
    string *ending;
    int *num1, *num2, *num3, *num4, *num5, *num6;
     char chr, chr1, chr2, chr3;



for(i= 0; i< sizeOfArray; i++)
    {
    getline(cin,opening[i]);
    cin >> num1[i] >> chr >> num2[i] >> num3[i] >> chr1 >> num4[i] >> chr2 >> num5[i] >> chr3 >> num6[i];
    getline(cin,ending[i]); 
    }

MY INPUT:
hello 1\2 3\4-5\6 bye

the code compile with no error, but it cannot read the first word,
while it only stores "1\2 3\4-5\6 bye"
how to get the first word??

Recommended Answers

All 7 Replies

should i add cin.ignore ??

using getline() two times doesnt help,,
is it the problem of for loop??

cin >> num1[i] >> chr >> num2[i] >> num3[i] >> chr1 >> num4[i] >> chr2 >> num5[i] >> chr3 >> num6[i];

What is that suppose to do?

read my input accordingly
hello 1\2 3\4-5\6 bye

num1 should read 1
chr -> \
num2 -> 2
.
.
.

oh my god,, i found that it can read the first word simply by cin >>
this topic can be closed :>

Review in your text the distinction between char * and string * -- I think you are very confused. Also, you are reading into a bunch of uninitialized pointers. Yikes.

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.