Click here to Skip to main content
15,887,746 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCreating an array out of txt file Pin
wzq2gn30-Aug-06 2:41
wzq2gn30-Aug-06 2:41 
AnswerRe: Creating an array out of txt file Pin
Cedric Moonen30-Aug-06 2:53
Cedric Moonen30-Aug-06 2:53 
AnswerRe: Creating an array out of txt file Pin
Hamid_RT30-Aug-06 2:54
Hamid_RT30-Aug-06 2:54 
AnswerRe: Creating an array out of txt file Pin
David Crow30-Aug-06 2:56
David Crow30-Aug-06 2:56 
GeneralRe: Creating an array out of txt file Pin
wzq2gn30-Aug-06 3:15
wzq2gn30-Aug-06 3:15 
GeneralRe: Creating an array out of txt file Pin
David Crow30-Aug-06 3:24
David Crow30-Aug-06 3:24 
QuestionRe: Creating an array out of txt file Pin
Zac Howland30-Aug-06 3:31
Zac Howland30-Aug-06 3:31 
AnswerRe: Creating an array out of txt file Pin
Stephen Hewitt30-Aug-06 15:50
Stephen Hewitt30-Aug-06 15:50 
Your code was incomprehensible and you didn’t explain properly what you were trying to do so I took a guess. You should spend some more effort making you code intelligible, especially if you’re asking others to look at it. Anyway forget about old C functions such as “fgetc” and raw arrays. Here’s my program in C++:
----------------------

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

int main(int argc, char *argv[])
{
using namespace std;

// Open the input file.
ifstream iff("C:\\a.txt");
if (!iff)
{
cerr << "Failed to open input file!" << endl;
return 1;
}

// We'll store the file's contents in a 'vector' of 'string's.
typedef vector<string> FileContents_t;
FileContents_t fileContents;

// Read in the file line by line and add each line to 'fileContents'.
string line;
while (getline(iff, line))
{
fileContents.push_back(line);
}

// Now we can access any character in the file by its row and column.
unsigned int column = 5;
unsigned int row = 4;
if (row>=fileContents.size())
{
cerr << "Row out of range!" << endl;
return 1;
}
const string &ourRow = fileContents[row-1];
if (column>=ourRow.size())
{
cerr << "Column out of range!" << endl;
return 1;
}
char c = ourRow[column-1];

// Output the results.
cout << "Char at row " << row << " column " << column << " is " << c << endl;

return 0;
}


Steve
AnswerRe: Creating an array out of txt file Pin
wzq2gn31-Aug-06 1:14
wzq2gn31-Aug-06 1:14 
Questionhow to proceed with Notification of emails using Mapi. Pin
uday kiran janaswamy30-Aug-06 1:54
uday kiran janaswamy30-Aug-06 1:54 
AnswerRe: how to proceed with Notification of emails using Mapi. Pin
David Crow30-Aug-06 3:09
David Crow30-Aug-06 3:09 
QuestionPath to current folder Pin
kajkow30-Aug-06 1:05
kajkow30-Aug-06 1:05 
AnswerRe: Path to current folder Pin
Nibu babu thomas30-Aug-06 1:10
Nibu babu thomas30-Aug-06 1:10 
GeneralRe: Path to current folder Pin
Waldermort30-Aug-06 1:33
Waldermort30-Aug-06 1:33 
GeneralRe: Path to current folder Pin
Programm3r30-Aug-06 1:37
Programm3r30-Aug-06 1:37 
GeneralRe: Path to current folder Pin
kajkow30-Aug-06 2:01
kajkow30-Aug-06 2:01 
AnswerRe: Path to current folder Pin
Waldermort30-Aug-06 1:25
Waldermort30-Aug-06 1:25 
AnswerRe: Path to current folder Pin
Kiran Pinjala30-Aug-06 1:27
Kiran Pinjala30-Aug-06 1:27 
AnswerRe: Path to current folder Pin
Programm3r30-Aug-06 1:27
Programm3r30-Aug-06 1:27 
AnswerRe: Path to current folder Pin
Hamid_RT30-Aug-06 2:18
Hamid_RT30-Aug-06 2:18 
QuestionSend mouse message to child window Pin
majco33330-Aug-06 0:58
majco33330-Aug-06 0:58 
AnswerRe: Send mouse message to child window Pin
prasad_som30-Aug-06 1:18
prasad_som30-Aug-06 1:18 
GeneralRe: Send mouse message to child window Pin
majco33330-Aug-06 1:22
majco33330-Aug-06 1:22 
AnswerRe: Send mouse message to child window Pin
Hamid_RT30-Aug-06 2:12
Hamid_RT30-Aug-06 2:12 
AnswerRe: Send mouse message to child window Pin
majco33330-Aug-06 2:12
majco33330-Aug-06 2:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.