Click here to Skip to main content
14,734,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have read from a file which are stored in a string array. i want to split string into several parts using stringstream, but this wont store anything and gives empty output for cout :/
        stringstream ssss;
ssss << arrayy[i];
getline(ss,line,' ');
first[i].country = line;
getline(ss,line,' ');
first[i].name = line;

but above does not give any output:
and av to use space as delimiter
Updated 25-Dec-12 6:01am
H.Brydon 3-Jan-13 1:24am
You have defined 'ssss' and are using 'ss' which is not defined in this portion of code. What does it look like?

Also, is it reasonable that there might be multiple space characters at the beginning of the file?

follow the below example :

#include <iostream>
#include <sstream>
using namespace std;

int main () {

  int val;
  stringstream ss (stringstream::in | stringstream::out);

  ss << "120 42 377 6 5 2000";

  for (int n=0; n<6; n++)
    ss >> val;
    cout << val*2 << endl;

  return 0;
        stringstream ssss;
ssss << arrayy[i];
ssss >>   first[i].country ;
ssss >>   first[i].name ;

but first test that your arrayy[i] contain just 2 words, or at last the 2 fisrt are the correct. (I´m assuming that country and name are members of type std::string or simmilar). This will eat not used spaces

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900