#include <iostream>
#include <sstream>
#include <string>
int main()
{
constexprchar COMMA = ',' ;
std::istringstream file(
" ORG 100\n"" LOAD X\n"" ADD Y\n"" STORE Z\n"" HALT\n""X, DEC 49\n""Y, DEC -80\n""Z, HEX 0000\n"
) ;
std::string line ;
while( std::getline( file, line ) )
{
std::cout << line << " (column one is: '" ;
std::string col_one ;
if( line.find( COMMA ) != std::string::npos ) // if a comma is found
{
std::istringstream stm(line) ; // put the line into a string stream
// read everything starting from the first non-whitespace character
// upto, but not including the comma
std::getline( stm >> std::skipws, col_one, COMMA ) ;
}
std::cout << col_one << "')\n" ;
}
}
I don't understand that. All I want it to do is separate that first column and put it in a file by itself. Here is my entire code so far, it won't separate anything.
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
int main()
{
usingnamespace std ;
constchar COMMA = ',' ;
ifstream sourceCode( "sourceCode.data" ) ;
ofstream symbolTable( "symbolTable.data" ) ;
std::string line ;
while( std::getline( sourceCode, line ) ) // read the file one line at a time
{
if( line.find( COMMA ) != std::string::npos ) // if the line contains a comma
{
std::istringstream stm(line) ; // put the line into a string stream
// read everything starting from the first non-whitespace character
// upto, but not including the comma into symbolValue
std::string symbolValue ;
std::getline( stm >> std::skipws, symbolValue, COMMA ) ;
symbolTable << symbolValue << '\n' ; // and write it to symbolTable
}
}
}