Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 30th, 2007, 01:12 PM
Registered User
 
Join Date: Nov 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default using a one line input for array

What I need to do is have input from one line (integers) and then put them into different variables... Let me explain with code:

THEORETICAL CODE:

Code:
#include <cstdlib>
#include <iostream>


using namespace std;

int main(int argc, char *argv[])
{
    int input[6];       //This will be the array for input

    cin >> input[];  //I know this wont work. What I want to do is
                     //the input will be seperated by comas... 
                     //ie: 1,2,3,4,5,6
                     //How can i do this so that the "1"
                     //goes into input[0].. the "2" into input[2]ect??

    system("PAUSE");
    return 0;
}

Get it? after that I take the numbers individually and put them into variables... but that is unimportant.


Thanks for all your help!!
~Nick

Reply With Quote
  #2 (permalink)  
Old January 1st, 2008, 06:17 PM
Authorized User
 
Join Date: Dec 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My first reaction would be to recommend building a function that would accept this a pointer to this array, and a pointer to the string input as arguments, something like that.

By using cin.getline instead of cin, you can specify which string array you want to use.

These arguments don't have to be pointers, but I think it's a good habit to avoid passing an array as an argument (the data), to lower the cost on stack memory usage.

But I'm just a newbie in C++ though, so take my recommendation for what it's worth ;)

Best regards,
Charles
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to draw indicator line in owc line chart AlexOo General .NET 0 July 9th, 2007 10:32 PM
Excel VBA "Sheets(array(. . .))" code line hsheldon Excel VBA 5 June 6th, 2007 09:55 AM
Reading line by line from a .txt file x_ray VB.NET 2002/2003 Basics 5 February 10th, 2006 01:55 PM
How to plot data from an array in a line chart ! Alseikhan Excel VBA 0 January 27th, 2006 12:22 PM
Ignore Comma in Line Input echovue Access 4 November 2nd, 2005 10:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.