Need Help for printing concatenating string ..

S

ssmile03

All,

Need HELP for below wrong output -


---
#include <iostream>
#include <sstream> // for ostringstream
#include <string>


using namespace std;

int main()
{
std::string name = "HELP";
string age = "01";
int count[10];
for (int x = 0; x < 5; x++) {
int result = 5;
result += count[x];
std::eek:stringstream out;
out << "The value is .." << name << age << result;
std::cout << out.str() << endl;
}
return 0;
}
--

The output is as -

The value is ..HELP012
The value is ..HELP011
The value is ..HELP014198113
The value is ..HELP011
The value is ..HELP011

while the required output should be -

The value is ..HELP011
The value is ..HELP012
The value is ..HELP013
The value is ..HELP014
The value is ..HELP015

Thanks!!
 
G

GGolf

<snip>
int main()
{
std::string name = "HELP";
string age = "01";
int count[10];
for (int x = 0; x < 5; x++) {
int result = 5;
result += count[x];
std::eek:stringstream out;
out << "The value is .." << name << age << result;
std::cout << out.str() << endl;
}
return 0;
}
What's wrong with simply using x+1 instead of result? You wouldn't need
either the count array or result in that case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

I need help 1
Crossword 2
I Need Fix In Code 1
Need help with this script 4
Need help for javascript code 3
Help with Loop 0
STL::MAP: Printing values only once .. 9
Concatenating multiple std::string's 15

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top