hello i am stuck at an IO problem and i need some help.
I need to read a file that i have but i want to parse it char by char and store the contents in an array.
in order to explain i have a file which has two columns, ie.
###############
A1 A2
B1 B2
and i want to store this values in a two-dimensional array.
I have managed to write the code to read the file and parse the data but i can do it line be line so i cannot distinguish where the A1 stops and where the A2 starts in order to put them in the second column of the array.
the code i have written up to now is just for reading the file and copying it from one file to another.
code:
#include "stdafx.h"
#include <iostream>
using namespace std;
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
int _tmain(int argc, char* argv[])
{
// Check for required arguments
if (argc < 2)
{
Console::WriteLine(S"Usage: CppReader path");
return 0;
}
// i have done it like that because i had problemreading the file from //the arguments but this can be solved
String* path = "\Full_data_linklist.txt"; //new String(argv[1]);
if (!File::Exists(path))
{
Console::WriteLine(S"Invalid filename!");
return -1;
}
try
{
//open file for reading
FileStream* fs = new FileStream(path, FileMode::Open);
StreamReader* sr = new StreamReader(fs);
//create new file for copying
FileStream* fs2 = new FileStream(S"dokimi2.txt", FileMode::Create);
StreamWriter* sw = new StreamWriter(fs2);
int count = 0;
for(;;)
{
String* line = sr->ReadLine();
count++;
// If there are no more lines, break out of the loop
if (line == 0) break;
Console::WriteLine(line);
// copy the text in another file
//copying line be line
sw->WriteLine(line);
}
// Close up the file
sw->Flush();
sw->Close();
Console::WriteLine(S"-- end --");
}
catch(System::Exception* pe)
{
Console::WriteLine(pe->ToString());
}
return 0;
}
if someone has any idea...:rolleyes:
thanks in advance ;)