CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    May 2015
    Posts
    540

    reading multiple lines into arrays

    Hello,

    I am just starting to solve a problem, with multiple arrays, something like:

    2,2
    1,2,3,4
    6,7,8,9,10
    0,2
    1,1

    +++++
    output:
    3, 7

    first line no of arrays and no of queries. 2nd and 3rd line, array contents. 4th and 5th querirs (i.e 0th array, 2and elem, 1st array, 1st elem)

    for that, i what is the good way to read input , ie ,may be use istream_iterator. But follwing startup program fails to compile !

    Code:
    	std::vector<int> vec;
    
    	std::string stringvalues = "125 320 512 750 333";
    	std::istringstream iss(stringvalues);
    
    	vec.emplace_back(std::istream_iterator<int>{ iss }, std::istream_iterator<int>{});
    
    Error C2440 'initializing': cannot convert from 'initializer list' to 'int'

    But when i try :
    Code:
    	std::string stringvalues = "125 320 512 750 333";
    	std::istringstream iss(stringvalues);
    
    	std::vector<int> vec(std::istream_iterator<int>{ iss }, std::istream_iterator<int>{});
    works ok !

    thanks a lot for comments and inputs

    Pdk
    Last edited by pdk5; September 21st, 2020 at 03:55 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured