0

So the "substr" command is used for extracting certain characters, i have a problem in which if the character is a space, the previous value is used for filling the variable
The code:

#include "stdafx.h"
#include<cmath>
#include<string>
#include<iostream>
#include<sstream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    string line="Introductory Chemistry";
    char character;

    for(int i=0;i<line.length();i++)
    {
        stringstream(line.substr(i,1))>>character;

        cout<<character<<endl;
    }

    cout<<endl;

    stringstream(line.substr(12,1))>>character;
    cout<<character;

    system("Pause");
    return 0;

the output should be each character printed out vertically, but where there is supposed to be a space, it is the previous character. The last bit proves this as 12 is the character that contains the space, but it returns the value "y". Further information is that no arrays can be used.

1
Contributor
1
Reply
6
Views
4 Years
Discussion Span
Last Post by sadben.khan
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.