•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,975 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 2,650 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: 1148 | Replies: 42 | Solved
![]() |
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,630
Reputation:
Rep Power: 8
Solved Threads: 168
hmmm.. That's not quite what I meant 
How about something like:
output:
When this code is finished, you will have a vector containing 5 integers. But you can add as much (..) numbers to the string and the vector will dynamically expand.
You can also use the GiveMeNumber() and Show() functions I posted in previous posts on this program.
This code might be a bit much for you, but if you have any question, just ask and I'll try to answer them.
You're using the (ancient) borland compiler right? Perhaps changing it to

How about something like:
cpp Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <sstream> #include <vector> using namespace std; int main() { vector <int> all_numbers; stringstream ss; string input = "1,2,3,4,5"; string buffer; int integer; ss << input; while (getline(ss,buffer,',')) { //convert buffer to int and put in 'integer' istringstream strin(buffer); strin >> integer; // integer now contains the numeric value of the buffer //so now push it in the vector all_numbers.push_back(integer); } cout << "Pushed " << all_numbers.size() << " numbers in the vector"; cin.get(); return 0; }
output:
Pushed 5 numbers in the vector
When this code is finished, you will have a vector containing 5 integers. But you can add as much (..) numbers to the string and the vector will dynamically expand.
You can also use the GiveMeNumber() and Show() functions I posted in previous posts on this program.
This code might be a bit much for you, but if you have any question, just ask and I'll try to answer them.
•
•
•
•
Ok few errors, ill tackle one at a time:
- Unable to open file <sstream>
You're using the (ancient) borland compiler right? Perhaps changing it to
#include <sstream.h> will work. But I'm not even sure if Borland already supported stringstreams.... I strongly suggest that you upgrade to a modern IDE+compiler as suggested in one of the other thread
Last edited by niek_e : Jul 18th, 2008 at 7:35 am.
Want better/more replies to your questions? Wrap your code in [code] [/code] tags!
do NOT pm me for help, in the best case, you'll get ignored
do NOT pm me for help, in the best case, you'll get ignored
Ok I have just downloaded and installed "Visual C++ 2008 Express".
Now it is giving me an error about the goto statement label. "xxxxx:" displaying "error C2143: syntax error : missing ';' before '}'".
Should I just try another compiler or ????
The code was working in Borland so I dont see why when I copy and paste it into VC++ that it should not work
Thanks, Regards X
Now it is giving me an error about the goto statement label. "xxxxx:" displaying "error C2143: syntax error : missing ';' before '}'".
Should I just try another compiler or ????
The code was working in Borland so I dont see why when I copy and paste it into VC++ that it should not work

Thanks, Regards X
"You never stop learning" - OmniX
•
•
Join Date: Jan 2008
Posts: 1,501
Reputation:
Rep Power: 7
Solved Threads: 189
•
•
•
•
Ok I have just downloaded and installed "Visual C++ 2008 Express".
Now it is giving me an error about the goto statement label. "xxxxx:" displaying "error C2143: syntax error : missing ';' before '}'".
Should I just try another compiler or ????
The code was working in Borland so I dont see why when I copy and paste it into VC++ that it should not work
Thanks, Regards X
Visual Studio 2008 Express should be able to handle niek's code. I can't imagine why it wouldn't. I copied and pasted niek's code into Dev C++ and it compiled and ran fine, and I did the same with Visual Studio 2008 (non-Express edition) and it did fine there too. I don't see any goto statements in niek's code. You started a console project, right? Try copying and pasting niek's code above into Visual Studio 2008 again and seeing if it compiles and runs. It should, I think. The error you list sounds like a typo somewhere, maybe?
Nothing wrong with niek_e code, its the one im working on.
I have changed compilers to codeblocks and its working no, so problem solved.
Onto the next one.
Im not sure If I have current brain freeze of trying to get my head around the new programming concept of C++ but from niek_e previous example I am trying to do exactly what he did BUT instead of just one variable I trying to break up the whole string into individual variables then compare them and then reattach all the variables as a string and add the "whole" variable to the string array.
Are you able to compare string vs. string in C++ or string vs. int?
Thanks, Regards X
PS: I apologize again about the newbieness
I have changed compilers to codeblocks and its working no, so problem solved.
Onto the next one.
Im not sure If I have current brain freeze of trying to get my head around the new programming concept of C++ but from niek_e previous example I am trying to do exactly what he did BUT instead of just one variable I trying to break up the whole string into individual variables then compare them and then reattach all the variables as a string and add the "whole" variable to the string array.
Are you able to compare string vs. string in C++ or string vs. int?
Thanks, Regards X
PS: I apologize again about the newbieness
"You never stop learning" - OmniX
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,630
Reputation:
Rep Power: 8
Solved Threads: 168
cpp Syntax (Toggle Plain Text)
//int c_same = 0; //strings string c_array_temp; string c_string; string c_temp; stringstream c_stringstream; //vectors vector<string> c_array; // Checks if 3 numbers are the same for (int numS= 0; numS< combinations_array.size(); numS++) { c_stringstream << c_array[numS]; for (int numB= 0; numB< combinations_array.size(); numB++) { getline(c_stringstream, c_temp,' '); c_array_temp >> c_temp; c_same = 0; // One if (one == c_array_temp || ) { c_same++; } // Two if (two == c_array_temp) { c_same++; } // Three if (three == c_array_temp) { c_same++; } // Four if (four == c_array_temp) { c_same++; } // Five if (five == c_array_temp) { c_sameme++; } // Six if (six == c_array_temp) { c_same++; } if (c_same > 3) { goto skip; } } // Writes the numbers to the string for (int numW=0; numW<6; numW++) { switch(numW) { case 0: c_string.append(one); c_string.append(" "); break; case 1: c_string.append(two); c_string.append(" "); break; case 2: c_string.append(three); c_string.append(" "); break; case 3: c_string.append(four); c_string.append(" "); break; case 4: c_string.append(five); c_string.append(" "); break; case 5: c_string.append(six); break; } } // Writes the numbers to the array c_array.push_back(c_string);
error: no match for 'operator<<' in c_array_temp << c_temp'| error: no match for 'operator==' in 'one == c_array_temp'| [happens for all one - six] error: no match for 'operator>>' in c_string >> one'|
Sorry I have tried my best to construct something but I have no luck

Hope you can help, Thanks Regards X
"You never stop learning" - OmniX
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,630
Reputation:
Rep Power: 8
Solved Threads: 168
Without looking trough all of your code, there are a few syntax errors, for example:
Also, the variables "one", "two", "three" etc are never declared....
I think you're making it to hard on yourself. If you want to break the string into integers and store them all, how about using the code I posted earlier?
You can access all the numbers in the array in the same way you would do it with an array:
would give the first number stored in the vector. If you understand how you can access the vector, the only thing you would have to do is to write a "compare-algorithm"
cpp Syntax (Toggle Plain Text)
if (one == c_array_temp || ) {
I think you're making it to hard on yourself. If you want to break the string into integers and store them all, how about using the code I posted earlier?
You can access all the numbers in the array in the same way you would do it with an array:
cout << all_numbers[0] ;
Want better/more replies to your questions? Wrap your code in [code] [/code] tags!
do NOT pm me for help, in the best case, you'll get ignored
do NOT pm me for help, in the best case, you'll get ignored
Ok i have decided to start again and break up my problem into little problems and solves them one by one and eventually and hopefully it is complete working order!!! 
Ok First Problem:
How do I get 6 variables and insert them into a string (seperated by spaces " ") and then it into an array?
Like This?
Now would the above code do what I require?
Thankyou, Regards X
PS: I am trying my best!!!

Ok First Problem:
How do I get 6 variables and insert them into a string (seperated by spaces " ") and then it into an array?
Like This?
cpp Syntax (Toggle Plain Text)
int a = 1; int b = 2; int c = 3; int d = 4; int e = 5; int f = 6; string abc; vector<string> abcd; abc << a << " " << b << " " << c << " " << d << " " << e << " " << f; abcd.append(abc);
Now would the above code do what I require?
Thankyou, Regards X
PS: I am trying my best!!!
"You never stop learning" - OmniX
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Arrays (C++)
- How to Return Multidimensional Arrays (C++)
- C file input/output 2D arrays. (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: making a simple c++ game
- Next Thread: Declare a 3D vector



Linear Mode